利用gcc编译选项和宏定义控制代码条件编译
示例代码(文件compile_macro_test.c):
#include <stdio.h>
int main()
{int a = 0;
#ifdef DBUG
a = 5;
#endifprintf("=========%d\n",a);
return 0;
}
对应Makefile文件
all:a.out
debug:b.out
mv b.out a.outa.out:compile_macro_test.c
gcc $< -o $@
b.out:compile_macro_test.c
gcc -DDBUG $< -o $@
.PHOHY:clean
clean:
rm *.out
运行make后得到的a.out输出为=========0
运行make debug后得到的a.out输出为=========5
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号