Sign in to follow this  
zyrolasting

[C++] Gigantic output

Recommended Posts

I've a project with a 7MB static library output. Executables that link to my library end up around 1MB. I tried to break things down a bit, but it didn't end well. I've done everything I could to shrink this monster in vain. I only depend on D3D(x)9, some STL containers and the WinAPI. Here's what I've done. - VC_EXTRALEAN - Used precompiled headers - Reduced template instantiations. (Each removal means a bunch of code to change) - Inlined only a few things - Split up projects (One 7MB library became 4 3MB ones) Please inform me of any other action I can add to that list short of tearing everything down. This is one of those "too big to fail" deals for me.

Share this post


Link to post
Share on other sites
7MB static library output doesn't sound so bad. Remember, the compiler can't go about optimizing the code too much, since it doesn't know what code you are using and what code you aren't. It'd be perfectly valid to pick some random, non-static function and use it in your linked code.
What you should be worrying about is the compile settings on the projects that link the library, because those are the projects that will be optimizing the code. Make sure to turn on full program optimizations, and optimize for size.

Share this post


Link to post
Share on other sites
Not really. Even though the static lib is 7MB, the final EXE should be much less. Just make sure "Eliminated Unreferenced Symbols" or whatever it's called is on. I think it's on by default.
Also turn on LTCG (Link-time code generation) for release builds.

Share this post


Link to post
Share on other sites
My lib is about 3 MB, at first I thought it was gigantic as well, but with C++ files are always bulky. Just multiply what you'd expect from a C application's size by 10, and you get a rough estimate what is reasonable for C++...

And yes, static linking FTW :)

Share this post


Link to post
Share on other sites

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