static Libraries

Started by
3 comments, last by the_edd 12 years, 4 months ago
Hi All, just a generic questions relating to static libraries.

If I create a static library A, which has code dependent on another static library B, then I use static library A in one of my Dll's, does it mean I dont have to include library B to my dll ?. In otherwords, will the dependent code in library B be burnt into library A, so library A will have its own code plus any additional code from library B ?

Will appreciate any help + links.
Thanks

KAZ.
Advertisement
Depends on how you configure your linker, but yes, you can do this. Just try it and you'll probably find that's how your compiler does it by default.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

If I create a static library A, which has code dependent on another static library B, then I use static library A in one of my Dll's, does it mean I dont have to include library B to my dll ?. In otherwords, will the dependent code in library B be burnt into library A, so library A will have its own code plus any additional code from library B ?


A good conceptual model for static library is "bundle of object files". So unless you've explicitly put all the objects from B in to A as well, you'll have to tell the linker about both of them. In fact if you're using the GCC linker, you'll also have to get the order right too. The Visual C++ linker tends not to be too fussy.
I had a question relating to this...

Say static library A depends on static library B full of useful utility functions.

Now also main project depends on both A and B. Is the executable bigger because library B is linked in twice or is it only linked in once?

Say static library A depends on static library B full of useful utility functions.

Now also main project depends on both A and B. Is the executable bigger because library B is linked in twice or is it only linked in once?

If both A and B are static libraries, there is not copy of B 'inside' A, so nothing is linked twice. In fact linking something twice will likely give you a linker error (depending on the linker) relating to the existence of multiple definitions for a bunch of symbols.

Again, you won't go far wrong if you think of a static library as a bundle of object files. Unless you've put copies of the same object files in both A and B, you won't have duplicate code/data anywhere.

This topic is closed to new replies.

Advertisement