Reputation: 621
I have a C++ preprocessor written like this:
#ifdef cpp_variable
//x+y;
#endif
How can I define this in Makefile?
Upvotes: 62
Views: 87466
Reputation: 309
If you want to do the below in a C/C++ file,
#define VARIABLE_NAME 2
then, in the Makefile, use the below lines:
CDEFS += -DVARIABLE_NAME = 2
Upvotes: -1
Reputation: 9150
The syntax is compiler-specific. For GCC, use the -D
option like so: -Dcpp_variable
.
Upvotes: 5
Reputation: 4038
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.
Upvotes: 40
Reputation: 564861
This is compiler specific.
GCC uses -Dcpp_variable=VALUE
or just -Dcpp_variable
Microsoft's compilers use /D
Upvotes: 62
Reputation: 752
Take a variable in Makefile and whatever you need to define in it just add -DXXX. Where XXX in you case is cpp_variable.
For example
COMPILE_OPTS = -DXXX
g++ -c $(COMPILE_OPTS) $<
Upvotes: 4