我想在 make 命令行中为 CC_FLAGS 定义值。
make - f makefile CC_FLAGS=-DVERSION='\"1.2.3\"'
可以,但是如果想为 CC_FLAGS 定义多个值怎么办?
make -f makefile CC_FLAGS='-DVERSION='\"1.2.3\"' -DVERSION_1_2_3'
这行不通。想法是有一个字符串告诉软件版本号以及#ifdef 用法的符号。
最佳答案
您不需要在现有的内添加额外的单引号。这有效:
make -f makefile CC_FLAGS='-DVERSION=\"1.2.3\" -DVERSION_1_2_3'
如本程序所示
int main (void)
{
printf ("Are we defined?\n");
#ifdef VERSION_1_2_3
printf ("yeah we have a version.\n");
#endif
#ifdef VERSION
printf ("version is: \"%s\"\n", VERSION);
#endif
return 0;
}
关于c - 制作命令行字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30493367/