如何在 Makefile 中定义 C++ 预处理器变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5213800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define C++ preprocessor variable in Makefile
提问by Joel
I have a C++ preprocessor written like this:
我有一个这样编写的 C++ 预处理器:
#ifdef cpp_variable
//x+y;
#endif
Can anyone tell me how to define this in Makefile.
谁能告诉我如何在 Makefile 中定义它。
回答by Reed Copsey
回答by fouronnes
Search your compiler documentation to find how to do that.
搜索您的编译器文档以查找如何执行此操作。
For example for g++
the syntax is :
例如g++
语法是:
g++ -Dcpp_variable <other stuff>
Which corresponds to adding
对应于添加
CPPFLAGS += -Dcpp_variable
in your makefile.
在你的生成文件中。
回答by Peter Tseng
Add to Makefile:
添加到生成文件:
CPPFLAGS = -Dcpp_variable
回答by Eugen Constantin Dinca
The syntax is compiler specific, for gcc use the -D
option like so: -Dcpp_variable
.
语法是编译器特定的,海合会使用-D
像这样的选择:-Dcpp_variable
。
回答by Akhil Pathania
Take a variable in Makefile and whatever you need to define in it just add -DXXX. Where XXX in you case is cpp_variable.
在 Makefile 中获取一个变量以及您需要在其中定义的任何内容,只需添加 -DXXX。在你的情况下,XXX 是 cpp_variable。
For example
例如
COMPILE_OPTS = -DXXX
COMPILE_OPTS = -DXXX
g++ -c $(COMPILE_OPTS) $<
g++ -c $(COMPILE_OPTS) $<