MSVC generates huge static libs

Started by
9 comments, last by Codeka 14 years, 1 month ago
The DLLs for my library are small (200k for release, 800k for debug), yet when I compile it statically, this shoots up to 6.5Mb for debug and 9.5 for release. I can't find any setting (VC2005) that could be affecting this, and am surprised that the release build is larger than debug. Does anyone have any ideas?
Advertisement
A shot in the dark: template instantiations inside your static libs.
Comparing .libs and .dlls isn't a valid thing to do. The program responsible for stripping unused and duplicated code is the linker - and that isn't run until you link your .lib files into either a .dll or a .exe.

As for release builds being bigger than debug builds, that's probably being caused by inlining.
Quote:Original post by Konfusius
A shot in the dark: template instantiations inside your static libs.

There's very little templated code in the library, certainly not enough to account for the size.

Quote:Original post by Nitage
Comparing .libs and .dlls isn't a valid thing to do. The program responsible for stripping unused and duplicated code is the linker - and that isn't run until you link your .lib files into either a .dll or a .exe.

As for release builds being bigger than debug builds, that's probably being caused by inlining.

Ah, good to know. Nonetheless, it's a relatively small library (about 13k lines of code) and I can't see how the resultant static lib is twice the size of say, OGRE's (which is a huge library with over a million lines).
There are linker options to reduce the output binary size (optimize for size, remove unused branches and all that stuff ...) in MSVC, and if not available as a checkbox then at least some option strings, but I can't recall them offhand as it was too long ago that I used MSVC for my own coding (at dayjob I still do, but there it's all set and done already :)).
CEGUI generates a 200MB static library for me :) My final exe compiles down to about 3.4MB at the moment, though, so I'm not too worried.

That's release mode. In debug mode, I actually get smaller .libs and larger .exes...
Quote:Original post by Codeka
CEGUI generates a 200MB static library for me :) My final exe compiles down to about 3.4MB at the moment, though, so I'm not too worried.

That's release mode. In debug mode, I actually get smaller .libs and larger .exes...

I guess I'll have to accept it, then. I thought I'd been doing something basic wrong, but maybe I shouldn't be worrying.
Sounds like one config has the CRT as linkable and the other config has it static.

The bigger one is bigger, but the smaller one means you need to redistribute the MSVC redist anyway, so I always link it right in whatever.
------------------------------Great Little War Game
Quote:Original post by Rubicon
Sounds like one config has the CRT as linkable and the other config has it static.

The bigger one is bigger, but the smaller one means you need to redistribute the MSVC redist anyway, so I always link it right in whatever.

It's all using the DLL CRT. This is for a library for redist isn't an issue.

Sorry, didn't fully read the question.

It does sound like you're missing out on "dead stripping" though. Have you tried linking everything static and see how much smaller it goes?
------------------------------Great Little War Game

This topic is closed to new replies.

Advertisement