GCC的DEBUG和release版本编译方法

来源:互联网 发布:vb眼镜 编辑:程序博客网 时间:2024/05/20 21:19
 
利用gcc的 -DDEBUG选项。
1. 源文件DEBUG.c中有:
#include <stdio.h>
int main(int argc, char *argv[])
{
#ifdef DEBUG
    printf("DEBUG is definded \n");
#else
    printf("DEBUG is not definded \n");
#endif
}
2. Makefile文件为:
DEBUG=
CFLAG= -g
debug: DEBUG.c
     gcc $(DEBUG) $(CFLAG) -o $@ $^

3. 输入:gcc -g -o debug DEBUG.c
               ./debug
   out: DEBUG is not definded
4. 输入:gcc -DDEBUG -g -o debug DEBUG.c
              ./debug
   out: DEBUG is definded

这样 DEBUG版本和 release版本都有了.
原创粉丝点击