如何在 Makefile 中添加#define?

新手上路,请多包涵

我有一个 c++ 项目,我需要在一些 CXX 文件中定义一个变量。我有近 800 个文件,我需要为 200 个文件定义一个变量。所以我想在makefile中定义它。那么我们怎么能做到这一点。

原文由 Akhil Pathania 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1k
2 个回答

使用可以使用头文件

定义.h:

 #define deff 10

main.cxx 或您要使用的任何文件

#include "definitions.h"

另一种方法是在编译时给出以下参数 g++ -DMYDEF file1.cpp file2.cpp —— file200.cpp -o abc.exe

原文由 user12551043 发布,翻译遵循 CC BY-SA 4.0 许可协议

Just add -Dxxx=yy on the command line ( xxx the name of the macro and yy the replacement, or just -Dxxx if there is no价值)。

它不是 Makefile 命令,它是编译器命令行选项的一部分。

原文由 Matthieu Brucher 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题