开发者

How to define C++ preprocessor variable in Makefile

I have a C++ preprocessor written like this:

  #开发者_JS百科ifdef cpp_variable
   //x+y;
  #endif

Can anyone tell me how to define this in Makefile.


This is compiler specific.

GCC uses -Dcpp_variable=VALUE or just -Dcpp_variable

Microsoft's compilers use /D


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.


Add to Makefile:

CPPFLAGS = -Dcpp_variable


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


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) $<

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜