将预处理器定义传递给 clang++

Pass preprocessor definition to clang++

给出

void foo() {
    int i = 0;
    #ifdef MACRO_A
         // custom behaviour
    #endif
    // program code
}

是否可以在编译时将#define MACRO_A传给clang++,让'custom behavour'语句生效?我找不到表明这在 clang++ 中可行的文档,但在其他编译器 (g++) 中是可能的。

感谢 pevasquez 的帮助,命令是

clang++ -D MACRO_A main.cpp -o main

函数

void foo() {
    int i = 0;
    #ifdef MACRO_A
         // custom behaviour
    #endif
    // program code
}

将编译包含预处理器指令部分中的代码。

这将是对我的 makefile 的补充,以创建调试友好的 make-chain 以及生产版本。