debug版本与release版本示例

来源:互联网 发布:飞机票图片制作软件 编辑:程序博客网 时间:2024/05/22 02:18

示例代码

#include <assert.h>#include <iostream>using namespace std;int main(){    int *p = NULL;    assert(p!=NULL);    cout << "123" << endl;    return 0;}

1)编译debug版本:g++ test.cpp -o test

生成文件:-rwxrwxr-x  1 hepeng hepeng 8.7K May  9 04:32 test

运行结果:

test: test.cpp:68: int main(): Assertion `p!=__null' failed.

Aborted

2)编译release版本:g++ test.cpp -o test -DNDEBUG -O2 -s

生成文件:-rwxrwxr-x  1 hepeng hepeng 5.3K May  9 04:35 test

运行结果:

123

说明:NDEBUG指明生成release版本,O2(大写o)指明二级优化(公认比较合理的),-s 表示 strip,去除二进制输出中的调试符号信息,减少生成的文件大小


原创粉丝点击