3

I wrote a static library (compiled with TDM-gcc 4.8.1 in Windows 7 for x64) that has dependencies on other static libraries. Boost libraries (locale and system) to be specific. Since I'm building a static library I assumed that the libraries I'm dependend on would automatically included in my final .a, especially since I'm using them in my code.

But when I'm trying to build an executable that statically links to my aforementioned library there are still undefined references to some boost parts, that are definitely used in my library.

Is there a way to fix that?

Any help is gladly appreciated. Thank you

Edit: I haven't been careful enough, because I now know what causes the problem. I'm using codeblocks and all the necessary arguments for building the archive are declared in the project prooperties. But codeblocks doesn't even call the linker when building my library. Instead it calls ar.exe and passes all object files of my project. That way, no external library are ever included. So, I have too look for away to tell codeblocks to build the library in the right way..

UsYer
  • 173
  • 1
  • 8

1 Answers1

4

Your executable needs to link against all the relevant libraries, including the ones it directly depends on, plus the ones it indirectly depends on. When you link a static library you typically do not embed other static libraries within it.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Tank you for your input. Hmm, I was under the impression that I encountered serveral projects where external libraries where somehow included in the library they provided. But I may be wrong here. In general, is there a way to include third party libraries in my own library? – UsYer Jan 17 '14 at 15:20
  • Not really. See http://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries for the details. You could write a tool to explode your depended-upon library back into object files (using `ar`, the same program which builds static libraries in the first place). Then you could link the resulting objects into your higher-level library. But this is not something anyone really does, and you probably shouldn't either. – John Zwinck Jan 17 '14 at 23:29
  • Okay, I see. Well then back to linking all the dependencies at once. Thanks, for your help – UsYer Jan 20 '14 at 09:49