My goal is to link libhelper.a into libtestlib.so. Is that possible on Linux?
Sure. This should do:
gcc -shared -fPIC -o libtestlib.so $(OBJS)
-Wl,--whole-archive -lhelper -Wl,--no-whole-archive
libhelper.a was not compiled with -fPIC
It's best to rebuild libhelper.a with -fPIC
. If that's not possible, above command will still work on Linux/ix86
, but not on e.g. Linux/x86_64
.
What is the proper way to build programs that use shared libraries that also have dependancies on static libraries?
If you include libhelper.a
into libtestlib.so
as above, then simple:
gcc main.c -ltestlib
is all you need. If you insist on linking with libhelper.a
, then you must tell the end-user that he must link with e.g.
gcc main.c -ltestlib -lhelper
There is no way to specify that libtestlib.so
depends on libhelper.a
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…