My goal is to link libhelper.a with libtestlib.so. Is this possible on Linux?
Of course. This should do:
gcc -shared -fPIC -o libtestlib.so $(OBJS) \ -Wl,--whole-archive -lhelper -Wl,--no-whole-archive
libhelper.a has not been compiled with -fPIC
It is best to rebuild libhelper.a with -fPIC . If this is not possible, the command above will work on Linux/ix86 , but not on. Linux/x86_64 .
What is the correct way to create programs that use shared libraries that also have dependencies on static libraries?
If you included libhelper.a in libtestlib.so as described above, simply:
gcc main.c -ltestlib
- thatβs all you need. If you insist on contacting libhelper.a , then you must tell the end user that he should link, for example,
gcc main.c -ltestlib -lhelper
It is not possible to indicate that libtestlib.so dependent on libhelper.a .
source share