Jump to content
  • Advertisement
Sign in to follow this  
Cluq

Static lib size

This topic is 3807 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

Hi I am creating a static (game) library in VC++. Up until now I have been using precompiled headers, e.g. all .cpp files included the precompiled header and all .h files included nothing. I didn't like the approach and decided to get rid of the precompiled headers. All .h and .cpp files were then updated with their appropriate includes and it all worked fine. But then I looked at the file size of my static library. It had grown from 5 MB to 22 MB! I first thought that I might have been including some other static library that got built into my library, but I haven't included any libraries. Can anyone enlighten me in what happened?! /Cluq.

Share this post


Link to post
Share on other sites
Advertisement
I'd assume that the precompiled headers cause the compiler to generate smaller code for them, which I guess makes sense, although I wouldn't expect such a vast difference.

Is your compiled exe (I assume you have a test exe) the same size as before?

Share this post


Link to post
Share on other sites
I do have a test.exe, but some refactoring have made it "uncompilable" at the moment..

Could anyone explain why the compiler generates smaller code using precompiled headers? - or perhaps throw a link...

Share this post


Link to post
Share on other sites
Quote:
But then I looked at the file size of my static library. It had grown from 5 MB to 22 MB!
Sorry, but this doesn’t compute. You may have accidentally set something to become a debug build or linked the wrong runtime, I don’t know.

A precompiled header doesn’t change code or anything. It’s about starting off from an intermediate step instead. Instead of working through the headers, the compiler has a file format it can automatically understand.

Share this post


Link to post
Share on other sites
Better question is - why does it matter?

Static libs will not be included verbatim, so whatever their size may be is irrelevant, compiled exe will be just as big as it needs to be.

Share this post


Link to post
Share on other sites
Quote:
Original post by oler1s
Sorry, but this doesn’t compute. You may have accidentally set something to become a debug build or linked the wrong runtime, I don’t know.


I thought so to, but I didn't change anything - I have run through the project settings twice :)

Quote:
A precompiled header doesn’t change code or anything.


That was also my belief, which made me ask the question in the first place.

Quote:
Original post by Antheus
Better question is - why does it matter?


If I have to distribute my library, I would prefer to distribute 5 MB instead of 22 MB.

Quote:
Original post by Marineio
The compiler (If you're using msvc++) will optimise it when you compile.


But all I did was to change from precompiled headers, so why did it not optimize the library?

It is still puzzling to me. I will try and recreate the situation again when I get the time.

Share this post


Link to post
Share on other sites
Your link-time code generation option changed (/LTCG).

With that enabled, linker is capable of doing further optimizations, such as inlining functions across library boundaries.

This means, that lib contains *everything*, even if never used. If you compile library without that, then it'll contain only things it knows will be used and are accessible by providing only public symbols.

The result is small library, but linking against such library will result in potentially slower code.

Share this post


Link to post
Share on other sites
It's not really a good idea to release compiled static libraries anyways, as you'd have to distribute different libraries for each compiler, each code generation setting, etc(If it's a C++ lib). Let the user compile it. The static lib size is meaningless.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
Your link-time code generation option changed (/LTCG).

With that enabled, linker is capable of doing further optimizations, such as inlining functions across library boundaries.

This means, that lib contains *everything*, even if never used. If you compile library without that, then it'll contain only things it knows will be used and are accessible by providing only public symbols.

The result is small library, but linking against such library will result in potentially slower code.


Thank you very much for that reply - that was what I was looking for :)

Quote:
Original post by DrEvil
It's not really a good idea to release compiled static libraries anyways, as you'd have to distribute different libraries for each compiler, each code generation setting, etc(If it's a C++ lib). Let the user compile it. The static lib size is meaningless.


Well, if you don't want to distribute the source, then what do you do? Distribute a .dll and the header files?

I thought static libs were a convenience to people, making them able to link my code into their exe, instead of linking to a .dll. Am I wrong here?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!