Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release mode static library much larger than debug mode version

Tags:

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

like image 395
PeterK Avatar asked Jun 23 '10 12:06

PeterK


1 Answers

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)

like image 125
sharptooth Avatar answered Sep 30 '22 01:09

sharptooth