利用gcc编译选项和宏定义控制代码条件编译


示例代码(文件compile_macro_test.c):

#include <stdio.h>

int main()
{

        int a = 0;
#ifdef DBUG
        a = 5;
#endif

        printf("=========%d\n",a);

        return 0;
}

对应Makefile文件

all:a.out
debug:b.out
        mv b.out a.out

a.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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM