简体   繁体   English

发布模式静态库比调试模式版本大得多

[英]Release mode static library much larger than debug mode version

today i found out that the compiled static library i'm working on is much larger in Release mode than in Debug . 今天我发现我正在处理的编译静态库在Release模式下比在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. 调试模式下的大小略大于3 MB(这是一个相当大的项目),但在发布时它最多可达到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. 我正在使用静态库项目的常规Visual Studio(2008)设置,在构建配置设置中几乎没有更改。 In release, i'm using /O2 and "Favor size or speed" is set to "Neither". 在发布时,我正在使用/ O2并且“赞成大小或速度”被设置为“不会”。 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? / O2(“最大化速度”)是否会导致最终的.lib比调试版本大得多,其中包含所有调试信息?

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 - 启用功能级别链接:是

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. 阅读编译器中的链接时代码生成一章- 每个程序员应该知道的关于 MSDN上编译器优化的内容 - 它基本上说,当LTCG打开时,编译器会生成更多的数据,这些数据被打包到静态库中,以便链接器可以使用它用于在实际链接可执行文件时生成更好的机器代码的额外数据。

Since you have LTCG off in Debug configuration the produced library is noticeably smaller since it doesn't have that extra data. 由于您在调试配置中关闭了LTCG,因此生成的库明显更小,因为它没有额外的数据。

PS: Original Link (not working at 11/09/2015) PS: 原始链接(不在2015年9月11日工作)

优化可能是这里的问题,特别是自动创建的inline函数将比调试更大但发布更快。

Personally I've never seen a release PDB be larger than a debug PDB. 就个人而言,我从未见过发布PDB比调试PDB更大。 Same deal for LIBs. LIB的相同交易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM