Skip to main content
GameDev.net gamedev.net
🔒 Locked

MSVC generates huge static libs

Started by Ajare Mar 1, 2010 at 11:59 AM 9 replies 2.4k views
Original Post
Ajare
Ajare
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?
Nitage
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.
Ajare
Ajare
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).
plastique
plastique
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 :)).
Codeka
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...
Ajare
Ajare
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.
rubicondev
rubicondev
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
Ajare
Ajare
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.

rubicondev
rubicondev
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
Codeka
Codeka
Quote:
Original post by Rubicon
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?
He's only talking about the size of the .lib file. Presumably the size of the final .exe/.dll is reasonable (like my example of CEGUI compiling to a 200MB static lib, but compiling to a final .exe size of 3.4MB).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.