发布模式静态库比调试模式版本大得多
今天我发现我正在处理的编译静态库在发布模式下比在调试模式下大得多。我发现这非常令人惊讶,因为大多数时候情况恰恰相反(据我所知)。
调试模式下的大小略高于 3 MB(这是一个相当大的项目),但在发布模式下它会增加到 6.5 MB。有人能告诉我这可能是什么原因吗?我对静态库项目使用常用的 Visual Studio (2008) 设置,在构建配置设置中几乎没有更改任何内容。在发行版中,我使用 /O2 并将“偏好大小或速度”设置为“两者都不是”。 /O2(“最大化速度”)是否会导致最终的 .lib 比包含所有调试信息的调试版本大得多?
编辑: 附加信息:
调试:
- 整个程序优化:无
- 启用功能级链接:无
发布:
- 整个程序优化:启用链接时代码生成
- 启用功能级链接:是
today i found out that the compiled static library i'm working on is much larger in Release mode than in Debug. I found it very surprising, since most of the time the exact opposite happens (as far as i can tell).
The size in debug mode is slightly over 3 MB (its a fairly large project), but in release it goes up to 6,5 MB. Can someone tell me what could be the reason for this? I'm using the usual Visual Studio (2008) settings for a static library project, changed almost nothing in the build configuration settings. In release, i'm using /O2 and "Favor size or speed" is set to "Neither". Could the /O2 ("Maximize speed") cause the final .lib to be so much larger than the debug version with all the debugging info in it?
EDIT:
Additional info:
Debug:
- whole program optimization: No
- enable function level linking: No
Release:
- whole program optimization: Enable link-time code generation
- enable function level linking: Yes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
差异具体是由于链接时代码生成造成的。阅读编译器 - 每个程序员都应该了解的有关编译器优化的链接时代码生成一章MSDN 上的 - 它基本上说,打开 LTCG 后,编译器会生成更多数据,这些数据会打包到静态库中,以便链接器可以在实际链接可执行文件时使用这些额外数据来生成更好的机器代码。
由于您在调试配置中关闭了 LTCG,因此生成的库明显较小,因为它没有额外的数据。
附:
原始链接(2015 年 11 月 9 日失效)
The difference is specifically because of link-time code generation. Read the chapter Link-Time Code Generation in Compilers - What Every Programmer Should Know About Compiler Optimizations on MSDN - it basically says that with LTCG turned on the compiler produces much more data that is packed into the static library so that the linker can use that extra data for generating better machine code while actually linking the executable file.
Since you have LTCG off in Debug configuration the produced library is noticeably smaller since it doesn't have that extra data.
PS:
Original Link (not working at 11/09/2015)
优化可能是这里的问题,特别是自动创建的内联函数将比调试更大但发布速度更快。
The optimization could be the issue here, notably automatically created
inline
functions will be bigger but faster in release than debug.就我个人而言,我从未见过发布 PDB 比调试 PDB 更大。 LIB 的交易也是如此。
Personally I've never seen a release PDB be larger than a debug PDB. Same deal for LIBs.