Sign in to follow this  

MSVC generates huge static libs

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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 :)).

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this