Skip to content

Please add a way to include project wide #defines within the IDE #1837

Not planned
@thepixy

Description

@thepixy

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:

  1. 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.
  2. A manual menu or IDE option to force a complete rebuild will aid in making this kind of per/project library customization work.

Activity

transferred this issue fromarduino/Arduinoon Jan 27, 2023
self-assigned this
on Jan 27, 2023
per1234

per1234 commented on Jan 27, 2023

@per1234
Contributor

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:

So 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.

locked as resolved and limited conversation to collaborators on Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @per1234@thepixy

      Issue actions

        Please add a way to include project wide #defines within the IDE · Issue #1837 · arduino/arduino-ide