Release mode static library much larger than debug mode version

风流意气都作罢 提交于 2019-11-27 17:24:32

问题


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


回答1:


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)




回答2:


The optimization could be the issue here, notably automatically created inline functions will be bigger but faster in release than debug.




回答3:


Personally I've never seen a release PDB be larger than a debug PDB. Same deal for LIBs.



来源:https://stackoverflow.com/questions/3101487/release-mode-static-library-much-larger-than-debug-mode-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!