Description
Problem: #defines in a sketch are only visible in subsequently #included .H files, but are not visible in library .CPP files associated with the included .H files.
Why it matters: I would like to be able to save code space by adding "#ifdef/#endif" constructs to library files, which would allow me to include or exclude code in that library from the project build. Unfortunately this is not possible in the typical case where a library contains both .H and .CPP files. #define(s) added to the top of a sketch will certainly be visible in .H files #included after the define(s). But they will not be visible in the .CPP file associated with the library's .H file! Even convoluted constructs where an included .H file responds to a defined identifier by creating another identifier will not result in the .CPP file being aware of those defines. This is especially true once the sketch has been compiled, because if there are no detected changes in the library's .CPP file, the source will be ignored in favor of the created object (.O) file.
Solutions requested:
- Please add the option to add or remove project wide defines, which all .H and .CPP files associated with included libraries will be guaranteed to be able to detect, with ordinary #ifdef directives.
- A manual menu or IDE option to force a complete rebuild will aid in making this kind of per/project library customization work.
Activity
per1234 commentedon Jan 27, 2023
Hi @thepixy. Thanks for taking the time to submit this suggestion.
I see we already have quite a few previous requests for this in various forms, including:
boards.txt
file not used in the compilation command arduino-cli#210So I'll close this as a duplicate. It is already possible to do what you propose if you are using the advanced tool Arduino CLI. If you would like assistance with using Arduino CLI, just post on the Arduino Forum:
https://forum.arduino.cc/c/software/arduino-cli/89
I'm sure we'll be able to help you out over there.