我编写了一个简单的 printf C 代码并制作了一个简单的 makefile。当我使用 CFLAGS、CPPFLAGS 和 LDFLAGS 运行 make 时,变量的值进入 cc 执行,然后是没有这些值的 gcc 执行,如下所示:
$ CFLAGS="-I." CPPFLAGS="-D TESTEDEFINE" CXXFLAGS="TESTECXXFLAGS" LDFLAGS="-L." LFLAGS="TESTELFLAGS" make
cc -I. -D TESTEDEFINE -L. teste.c -o teste
gcc -o teste teste.c
当我运行构建的程序时,没有定义定义,因为它给了我未定义的#else的printf。
teste.c
#include <stdio.h>
int main()
{
#if defined(TESTEDEFINE)
printf("TESTEDEFINE!!!");
#else
printf("!!!");
#endif
return 0;
}
生成文件
all: teste
gcc -o teste teste.c