2024-01-23 01:29 AM
I'm trying to change a preprocessor value when building a project through the command line headless build.
I can add a value through the command line using -D MY_VAL=10 which works fine if that value has not previously been defined.
But I would like to have a default value defined in the IDE and then optionally overwrite it when using the command line. Setting a value in "Project Properties > C/C++ Build > settings > GCC Compiler > preprocessor" means that value will be used and the value from the command line headless build will be ignored.
Is there a way to have a default value and overwrite it through the command line? Thanks,
Solved! Go to Solution.
2024-01-23 01:35 AM
How about:
#if !defined YOUR_SYMBOL
#define YOUR_SYMBOL <your value>
#endif
So, if it's defined on the command line, the command-line definition will be used; otherwise the definition in the code will be used.
2024-01-23 01:35 AM
How about:
#if !defined YOUR_SYMBOL
#define YOUR_SYMBOL <your value>
#endif
So, if it's defined on the command line, the command-line definition will be used; otherwise the definition in the code will be used.
2024-01-23 01:41 AM
That's it, Thanks.
2024-01-23 01:47 AM
The same approach also works with symbols which may or may not be defined in the IDE project.
If there's a symbol which needs to be defined on the command line (or in the IDE Project), but doesn't make sense to have a hard-coded default in the code, you could do:
#if !defined YOUR_SYMBOL
#error "YOUR_SYMBOL must be defined!"
#endif