How to define C++ preprocessor variable in Makefil

2020-02-08 05:13发布

I have a C++ preprocessor written like this:

  #ifdef cpp_variable
   //x+y;
  #endif

Can anyone tell me how to define this in Makefile.

标签: c++ makefile
5条回答
【Aperson】
2楼-- · 2020-02-08 05:21

This is compiler specific.

GCC uses -Dcpp_variable=VALUE or just -Dcpp_variable

Microsoft's compilers use /D

查看更多
欢心
3楼-- · 2020-02-08 05:26

Add to Makefile:

CPPFLAGS = -Dcpp_variable
查看更多
一夜七次
4楼-- · 2020-02-08 05:37

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.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2020-02-08 05:41

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

查看更多
我欲成王,谁敢阻挡
6楼-- · 2020-02-08 05:47

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

查看更多
登录 后发表回答