Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include a static library in a static library - CodeBlocks

I'm having an issue compiling a static library using Code::Blocks 13.12. I need to use a third party static library from within my own static library. So, I have libOtherLib.a and I'm trying to build libMyLib.a and link in libOtherLib.a. The problem is that the linker is not including libOtherLib.a during the linking phase of the build. Here is some additional information:

  • I am using the GNU GCC Compiler

In Project build options for the whole project (not specifically Debug or Release)

  • I have added libOtherLib.a in the Link Libraries list in the Linker Settings
  • I have added the path to libOtherLib.a in the Search directories -> Linker list
  • I have added the path to the .h file for libOtherLib.a in the Search directories -> Compiler list

  • The library compiles completely fine (produces bin/Debug/libMyLib.a with no errors)

Any help would be greatly appreciated. I have an inkling that it is related to this being a Static Library rather than an application (console or otherwise), but I'm not sure how or why. I did change the build target Type to "Console Application" in the Project Properties window and it looked like it was linking in libOtherLib.a, but it had other errors because this code is meant to be a library rather than an application.

Here is the linker command that is executed at the end of the build. libOtherLib.a is not there anywhere, that is the problem, just not sure what the solution is.

ar -r -s bin/Debug/libMyLib.a <all of my .o files> 

Possible causes of the problem would also be nice - if this is mostly like the compiler, the linker, the setup or Code::Blocks itself.

like image 879
ang mcg Avatar asked Dec 02 '25 17:12

ang mcg


1 Answers

When building a static library you are just putting together a bunch of object files into an entity easier to ship and use. There is no linking done when building a static library.

The unresolved references from your library are dealt with when building an application or certain shared objects. You'd just ship your library and require that users also supply the library your library deoends on when building.

If you want to include the library you are depending on in your library you can extract the object files from tgat library and include them into your library. Although technically possible it is questionable if you have the rights to do so. Also, that is normally not the way things are done and I'd recommend against doing so.

like image 100
Dietmar Kühl Avatar answered Dec 05 '25 05:12

Dietmar Kühl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!