How to define C++ preprocessor variable in Makefile

I have a C++ preprocessor written like this:

  #ifdef cpp_variable
   //x+y;
  #endif

Can anyone tell me how to define this in Makefile.


Solution 1:

This is compiler specific.

GCC uses -Dcpp_variable=VALUE or just -Dcpp_variable

Microsoft's compilers use /D

Solution 2:

Search your compiler documentation to find how to do that.

For example for g++ the syntax is :

g++ -Dcpp_variable <other stuff>

Which corresponds to adding

CPPFLAGS += -Dcpp_variable

in your makefile.

Solution 3:

Add to Makefile:

CPPFLAGS = -Dcpp_variable

Solution 4:

The syntax is compiler specific, for gcc use the -D option like so: -Dcpp_variable.