views:

94

answers:

3

Hi everyone,

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

A: 

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

Billy ONeal
+1  A: 

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

Shane MacLaughlin
+3  A: 

The difference is specifically because of link-time code generation. Read this detailed explanation 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.

sharptooth
Thank you, this explained a lot!
PeterK