Skip to content

Fix multiple definition errors when using library header in two different files #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

maxgerhardt
Copy link
Contributor

@maxgerhardt maxgerhardt commented Apr 19, 2023

Since this library defines the Breakout object in its header file, it's a death sentence for users wanting to use the header file from two different .cpp files, as such is common in IDEs like PlatformIO + VSCode, since that causes multiple definition of errors.

Users are running into this error for example here.

This PR fixes this error by only declaring the breakout object to be extern and then adding a .cpp file in which the object is then created once.

@github-actions
Copy link

Memory usage change @ a3ffef2

Board flash % RAM for global variables %
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/BreakoutRTCGet
flash
% examples/BreakoutRTCGet
RAM for global variables
% examples/BreakoutRTCSet
flash
% examples/BreakoutRTCSet
RAM for global variables
% examples/BreakoutWebServer
flash
% examples/BreakoutWebServer
RAM for global variables
% examples/GpioManagement
flash
% examples/GpioManagement
RAM for global variables
% examples/LM75BTemperature
flash
% examples/LM75BTemperature
RAM for global variables
% examples/PDMRootMeanSquare
flash
% examples/PDMRootMeanSquare
RAM for global variables
% examples/analogRead
flash
% examples/analogRead
RAM for global variables
% examples/analogWrite
flash
% examples/analogWrite
RAM for global variables
%
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/BreakoutRTCGet<br>flash,%,examples/BreakoutRTCGet<br>RAM for global variables,%,examples/BreakoutRTCSet<br>flash,%,examples/BreakoutRTCSet<br>RAM for global variables,%,examples/BreakoutWebServer<br>flash,%,examples/BreakoutWebServer<br>RAM for global variables,%,examples/GpioManagement<br>flash,%,examples/GpioManagement<br>RAM for global variables,%,examples/LM75BTemperature<br>flash,%,examples/LM75BTemperature<br>RAM for global variables,%,examples/PDMRootMeanSquare<br>flash,%,examples/PDMRootMeanSquare<br>RAM for global variables,%,examples/analogRead<br>flash,%,examples/analogRead<br>RAM for global variables,%,examples/analogWrite<br>flash,%,examples/analogWrite<br>RAM for global variables,%
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@aentinger aentinger merged commit ff673e9 into arduino-libraries:main Apr 19, 2023
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants