Release mode static library much larger than debug mode version
Asked Answered
G

3

21

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

Glottochronology answered 23/6, 2010 at 12:19 Comment(1)
What about "whole program optimization" and "function-level linking" settings in both configurations?Orleanist
O
33

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)

Orleanist answered 24/6, 2010 at 6:8 Comment(1)
Thank you, this explained a lot!Glottochronology
S
1

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

Scribe answered 23/6, 2010 at 12:28 Comment(0)
R
0

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

Revivalist answered 23/6, 2010 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.