Reputation: 11
I've got two shared libraries libA and libB, and I want to create a new library libC, that links to both libraries, so I can link my application with -lC instead of -lA and -lB. I can't use -lA and -lB one, because I'd have to fix many packages otherwise.
libB is a precompiled binary.
I tried to run this:
gcc -fPIC -shared -o libA.so A.c
gcc -shared -Wl,--no-as-needed -L. -lA -lB -o libC.so
But when I link my application, that needs libB with -lC I
App.o: undefined reference to symbol 'SymbolInB'
note: 'SymbolInB' is defined in DSO libB.so
so try adding it to the linker command line
libB.so: could not read symbols: Invalid operation
If I run readelf -a libB.so
I see the SymbolInB in .dynsym, it is missing in libC.so. So I assume I miss a linking option to resolve the symbols correctly?
Upvotes: 1
Views: 832
Reputation: 409472
It doesn't work that way. The functions in libC
can use the functions in libA
and libB
fine, because libC
was linked with the other libraries. However, those symbols from libA
and libB
are not exported from libC
, so if you have an application which directly uses functions from libB
then you need to link with libB
.
Upvotes: 2