views:

320

answers:

3

I have a static lib A, which also uses static libs B, C and D.

I then have applications X and Y which both use A, but not B, C or D.

Is there some way to make it so X and Y will automatically see that A used B, C and D and link them, so that I don't need to keep track for the entire dependency tree so I can explicitly pass every static lib (quite a lot with things like Windows, Boost, etc)?

A: 

The easy way is to always offer the particular libraries A, B, C, and D to be linked. For a true library, the linker only retrieves the modules needed.

The key problem with A having some implicit linkage to other libraries is that they aren't necessarily uniquely identifiable. For example, should it use version 2.0 or 3.1? The one in /usr/share/lib or the one in /usr/lib/X11/xdm/share/lib? Etc.

wallyk
THe problem is with things like boost its hard for X to know which boost libaries A used and if X didnt happen to use the same boost library linker errors, hence the reason I want it to automatcally link it. If A used say 1.38 of boost and X 1.40 of boost its going to cause problems regardless of weather the linking of that specfic component was automatic, or by me going through the considerable effort of working out which boost libaries A used.
Fire Lancer
The disadvantage with this is of course extended link times.
anon
+2  A: 

Static libraries do not link with other static libraries. Only when building the executable (or shared library/DLL) is linkage performed, and the way to keep track of this is (of course) to use make.

anon
+1  A: 

I think, conceptually, you might be able to merge libs together to achieve what you want - they are after simply collections of symbols ready made for the linker. Having said that, I've never seen a tool to do it. The binary format of a lib is a compiler matter, so it would have to be a mingw or gcc specific tool.

In terms of knowing which version of Boost lib A uses, there isn't really much for it but to find the documentation for A.

Matt Gordon
If you use the GCC compiler (or other UN*X/Linux compilers) you can use the ar tool to manipulate static libraries. On these platforms, libraries are simply concatenated object files, with an optional index. But whether creating a mega library from multiple smaller libraries is a good idea is another matter.
anon