cancel
Showing results for 
Search instead for 
Did you mean: 

Change preprocessor values with headless build?

Tom_y
Associate

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,

1 ACCEPTED SOLUTION

Accepted Solutions

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.

 

View solution in original post

3 REPLIES 3

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.

 

Tom_y
Associate

That's it, Thanks.

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