AbsolutelyFreeWeb
AbsolutelyFreeWeb

Reputation: 405

Visual C++ size of debug and release version on a static library

I have same question as: dll size (debug and release) but I'd like to investigate this further.

My code is just one .h 2kb and one .cpp 14k file. the resulting debug lib is 185 kb made with

/GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"Debug\vc110.pdb" /fp:precise /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MTd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\lib_yyy.pch" 

my release version is 2275 kb

/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc110.pdb" /fp:precise /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MT /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\lib_yyy.pch" 

so I tried to optimize for size instead of speed and turn off inline expansion anticipating something similar to debug version (O1 and Ob0 instead of O2):

/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O1 /Ob0 /sdl /Fd"Release\vc110.pdb" /fp:precise /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MT /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\lib_yyy.pch" 

the resulting size : 2275 kb... wait.. what ???

if I do dumpbin headers on the debug version, I get lots and lots of lines, on the release version, all size comes out in one small anonymous paragraph.

so how do I check what takes all this space ? and how does it make sense that optimizing for speed and size gives the same size and that size is way bigger than not being optimized at all AND carrying extra debug information?

Upvotes: 0

Views: 374

Answers (1)

zeromus
zeromus

Reputation: 1667

"Generate map file" in the linker options is the universal way of debugging "why is this so large" questions, but since you're asking about a lib, that won't work. Not so many people care about the size of a lib. I suspect most people concerned about the size of the lib are confused and really should be concerned about the size of the exe. But maybe you're an exception.

I won't waste time philosophizing about what might could in theory cause release mode codegen to be larger.

Most likely what's causing your problem is, "whole program optimization" and "link time code generation". (see /GL in commandlines.) With those, the release mode object files are emitted basically halfway-finished, so they're not baked down anywhere near as small as they could be. The baking down occurs during linking, and that's where most people analyze the size of their code.

Minimal rebuild may be muddling your analysis as well.

Upvotes: 1

Related Questions