为make中的所有文件定义预处理器变量

mta*_*med 10 c gcc makefile c-preprocessor

通过将代码块放在预处理器指令中,我有许多.c.h文件禁用了代码的某些部分,例如

#ifdef FOOBAR
// some code that can be compiled if needed by defining FOOBAR in pre-processor.
#endif
Run Code Online (Sandbox Code Playgroud)

不,我需要FOOBAR定义为gcc使用的每个文件定义的make.

有没有办法做一些选项来做或Makefile

谢谢.

Jen*_*edt 16

将编译器选项添加-DFOOBAR到make变量CFLAGS

  • @mtahmed,有.只需将变量定义放在make的命令行上,`make CFLAGS =' - O3 -march = native -DFOOBAR'` (5认同)
  • 应该注意的是,这不仅仅是一个gcc-ism,而是C编译器调用的POSIX标准的一部分. (4认同)