结论:Gcc中并没有Release和debug版本之分,只有编译选项的组合

大学时候使用VS开发,VS编译的程序是可以选debug或者release的,搞得我一直误以为使用gcc编译,也有这种区分。


详细介绍

1 优化参数 -Os的使用

Note that gcc doesn’t have a “release mode” and a “debug mode” like MSVC does. All code is just code. The presence of the various optimization options (-O2 and -Os are the only ones you generally need to care about unless you’re doing very fine tuning) modifies the generated code, but not in a way to prevent interoperability with other ABI-compliant code. Generally you want optimization on stuff you want to release.

没有特别需求的情况下,gcc编译选项你只需要关注-Os这个选项,这个选项主要是对代码做优化的。

  1. -O0,-O1: the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.
  2. -O2:Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O, this option increases both compilation time and the performance of the generated code.
  3. -O3:Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the extended optimization flags.

根据我已知的资料,O3的优化在某些时候可能会有问题,gcc对O3的实现估计有问题,所以最好只用到O2,O3不要用

2 调试信息的产生:-g

The presence of the “-g” option will cause extended symbol and source code information to be placed in the generated files, which is useful for debugging but increases the size of the file (and reveals your source code), which is something you often don’t want in “released” binaries.

But they’re not exclusive. You can have a binary compiled with optimization and debug info, or one with neither.

-g只是说要不要导出符号表到程序里面,它可以跟 -0s组合使用,比如:-O2 -g,即优化代码又导出符号表。

有时候我们使用了-g,使用gdb调试的时候,会出现“No symbol xxx in current context”
这样的问题。
这是因为比较新的gcc版本导出的符号格式默认是DWARF4,比较老的gdb版本无法识别这种格式。
这种问题可以通过加 -gdwarf-2或者-gdwarf-3告诉gcc,产生老版本的符号信息,这样老版本的gdb就
能识别

reference

[1] https://stackoverflow.com/questions/1534912/how-to-build-in-release-mode-with-optimizations-in-gcc

[2] http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

gcc中的debug版本和release版本相关推荐

  1. c++中的Debug版本和Release版本的区别

    今天看Visual C++ 2012 入门经典,书上描述: Debug版本包括帮助用户调试程序的信息,使用程序的Debug版本,可以在出现问题时单步执行代码,以检查程序中的数据值. Release版本 ...

  2. Cmake生成debug版本和release版本

    在Visual Studio中我们可以生成debug版本和release版本的程序,使用Cmake我们也可以达到同样的效果.debug版本的项目生成的可执行文件需要有调试信息并且不需要进行优化,而re ...

  3. 蠢哭了,debug版本可用release版本出错

    记录一下本人遇到的问题,可能不适用于各位. win10 vs2015  MFC编写的一个动态库dll工程,debug版本release版本编译都通过.但是运行时debug版本可用 release版本出 ...

  4. Maven的Snapshot版本与Release版本

    1. Snapshot版本代表不稳定.尚处于开发中的版本 2. Release版本则代表稳定的版本 3. 什么情况下该用SNAPSHOT?  协同开发时,如果A依赖构件B,由于B会更新,B应该使用SN ...

  5. snapshots版本和release版本间的区别

    snapshots版本和release版本间的区别 在java开发过程中,我们经常会看到代码仓库中的某些项目版本以release或snapshots结尾,一般来说snapshots版本代表正在开发中的 ...

  6. snapshots版本和release版本区别

    snapshot版本和release版本区别 在java开发过程中,我们经常会看到代码仓库中的某些项目版本以release或snapshots结尾,现在说说这两个版本之间有什么区别. 一般来说snap ...

  7. Maven 的 Snapshot 版本与 Release 版本

    Maven 的 Snapshot 版本与 Release 版本 1.Snapshot 版本代表不稳定.尚处于开发中的版本. 2.Release 版本则代表稳定的版本. 3.什么情况下该用 SNAPSH ...

  8. VS.Net中程序集的Debug版本和Release版本的区别

    作者:未知   请作者速与本人联系 前几天看到豆腐的文章介绍如何知道程序集是Debug版还是Release版,之前只知道某些软件从功能上有企业版.标准版之分,却从不知道.Net程序集还有Debug和R ...

  9. VC++调试程序、快捷键以及Debug版本与Release版本

    1.如何在Release状态下进行调试 Project->Setting=>ProjectSetting对话框,选择Release状态.C/C++标签中的Category选General, ...

最新文章

  1. 请问,关闭子窗口提示错误,大家遇到这样的问题吗?
  2. KDD Cup 2021城市大脑赛题解析!报名倒计时3天
  3. 意大利物联网技术发展现状
  4. 如何用计算机画立方体,画立方体-计算机图形学实验.doc
  5. 数论 - 简单数位推理 --- NYIST 514
  6. 【大会】5G现象级应用倒计时24个月
  7. HDU4372 Count the Buildings
  8. 【牛客 - 157E】青蛙(floyd最短路,建图)
  9. [MySQL]--查询性能分析工具-explain关键字
  10. 312. Burst Balloons
  11. 清风老师数学建模笔记——层次分析法
  12. python二进制转换为16进制
  13. 免费的asp.net 2.0空间
  14. 郑捷《机器学习算法原理与编程实践》学习笔记(第六章 神经网络初步)6.3 自组织特征映射神经网路(SOM)...
  15. 如何维持手机电池寿命_如何延长手机电池寿命?总有些事你不知道
  16. 双系统(win10+ubuntu)引导页消失
  17. opengles之展翅飞翔的雄鹰
  18. Windows——卸载MinGW的方法
  19. android app增加内存大小,硬件不够软件来凑:如何提升Android手机运行内存?
  20. zabbix Trapper 监控项配置

热门文章

  1. ES6 Generator实现协同程序
  2. Markdown语法入门练习
  3. 【转】Gartner:2011十大战略技术 云计算居首
  4. 程序员、架构师、技术经理、技术总监和 CTO 都是干什么的?
  5. reflow和repaint
  6. 【codeforces 746A】Compote
  7. java实习生面试题_java实习生面试题大全(2019年整理)
  8. oracle数据库添加表空间
  9. FreeMaker模板引擎
  10. 利用STM32CubeMX软件生成USB_HOST_CDC驱动ME909s-821ap(4G通信模块)