Question

Suppose that I need libA.a in my application. libA.a needs libB.a itself and I need to statically link to both of them in my application. In order to eliminate this, I merge these two (libA.a and libB.a) to have libAB.a (this is done using ar tool). No issue yet.

When I want to run my application (which is linked to libAB.a) compiler starts complaining about undefined references to methods in libA that are using libB! When I link app to libB.a in addition to libAB.a everything is OK! According to file sizes it seems that libAB.a is result of merge of libA and libB but at compile time it seems that only libA is available to the application.

Here is the merge command:

ar rcus -v ../lib/libPocoFoundationmtd.a @"Foundation.txt" "c:/MinGW/lib/libiphlpapi.a"

Foundation.txt contains a list of .o files which will create a .a file. And here is the compile command for my application:

g++ -o ./Debug/exe1 @"exe1.txt" -L. -Lc:/poco/lib/  -lPocoFoundationmtd
Was it helpful?

Solution

Seems that I have found the solution! I was mixing .o and .a files together (object files + static libraries) inside merged .a file. I did ar-x to extract contents of .a file and then I merged all .o files into one final merged.a library

Sorry for the delay :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top