cancel
Showing results for 
Search instead for 
Did you mean: 

Preprocessor Macro file does not work for me

JWend.1
Associate II

Hello Everyone

I'm trying to use Preprocessor Macro Files but they do not seem to work for me.

JWend1_1-1699266268853.png

 

I add the file path to a .h header with a couple of defines that I would like to use globally here.
When I build the project, these defines are not found.

Things I tried to fix this, without success:
- Clean and rebuild
- Restart of IDE
- Added the file to both GNU C and Assembly together and separate
- Using Project, Workspace or File System Path

What am I missing to make this work?
Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

Put dummy placeholders in the prerpocessor sections.  For example, "FIRMWARE_VERSION=xxx".  Then create a script that the CI/CD tool runs that edits the ".cproject" file to put the real values there.  Remember if your project uses C++, you will need to put them in two places (for each build type, i.e. "debug", "release", etc.)

View solution in original post

8 REPLIES 8
Bob S
Principal

I've never tried to use that, interesting concept.  Maybe check the "treat as built-in" checkbox?

Other than that, stuff that I want defined everywhere usually gets added to the compiler settings in the "Preprocessor" section.  That is a bit of a pain as you need to replicate defines in both the "GCC Compiler" and "G++ Compiler" sections.  But it works.

JWend.1
Associate II

Okay, I tried to enable the "treat as built-in" option, but unfortunately that doesn't work.
I can't add my defines to the "Preprocessors" defines because "Version.h" is a file that is generated in our CI/CD pipeline. It contains the current version of the code depending on the git tag. Is there another way to automatically update the "Preprocessor" defines?

Bob S
Principal

Put dummy placeholders in the prerpocessor sections.  For example, "FIRMWARE_VERSION=xxx".  Then create a script that the CI/CD tool runs that edits the ".cproject" file to put the real values there.  Remember if your project uses C++, you will need to put them in two places (for each build type, i.e. "debug", "release", etc.)

JWend.1
Associate II

Yes that works. Thank you!

Should I open a bug report or do anything else regarding the Preprocessor Macro File?

Bob S
Principal

> Should I open a bug report

Sure, if you want.  Maybe add "BUG" tag to this thread (if you can).  Else create a new thread and reference this one.

I just realized that most paths in the IDE are relative to the Debug or Release directories, not from the project root directory.  For example, the GCC compiler "Include Paths" config uses "../Core/Inc" (note the leading "..").  Maybe try adding that to your preprocessor macro file path.  Though I would have expected an error or diagnostic message if the IDE couldn't find the file.

Pavel A.
Evangelist III

If you want to add include path (-I) please use this setting: C/C++ General->Paths and symbols-> Languages->GNU C (or C++) -> Include directories.  If you want to add macros (definitions, -D...):  again C/C++ General->Paths and symbols-> Languages->GNU C (or C++) -> Symbols.

Do not use "Preprocessor include paths, Macros..." It does not seem to work. Tweaking there is not helpful but can do harm. No need to open bug requests on that. It is part of upstream Eclipse CDT, should be dealt with there.

 

Another (working) way to change the include paths is C++ Build-> Settings, Click Tool settings tab.

Then MCU GCC (or C++) compiler-> Include paths and Preprocessor.

> Do not use "Preprocessor include paths, Macros..." It does not seem to work.

That is unfortunate to hear.

> It is part of upstream Eclipse CDT, should be dealt with there.

Thank you for pointing me to the correct source. I will make a new post there.

 

Pavel A.
Evangelist III

Actually I don't even understand the purpose of these things in  "Preprocessor include paths, Macros etc.".

 Looks like there are several "providers" of preprocessor macros and so on. One of these, "CDT managed build settings entries" adds "DEBUG" in the Debug configuration of CDT projects. "CDT User Setting entries" is the only item where the "Add..." button is enabled. But it is not clear how to add anything there (tried several things, nothing worked). It looks like internals of CDT that provide proper settings for the used toolchain and project nature(s). Not touching that with a long pole.