I want to use gcc to produce a shared library, but i want to link some other libraries it depends on statically. Now to produce the "standard" dynamically linked output file i use
gcc -dynamiclib *.o -lfoo -lbar -o outfile
which would be
gcc -shared *.o -lfoo -lbar -o outfile
on for a binutils ld
on a linux system. Now if i want libfoo and libbar to be linked statically, I can name the static libraries directly
gcc -dynamiclib *.o /usr/lib/libfoo.a /usr/lib/libbar.a -o outfile
however, that way i have to look for the library files myself. GNU binutils ld
supports this:
gcc -shared *.o -l:libfoo.a -l:libbar.a -o outfile
but apple's ld
doesnt.
- Is there a way to make apple's
ld
look for the static libraries himself?
- If not, is there another way that would avoid naming the exact location of the archives, e.g. producing an intermediate output file out of the object files requiring libfoo and libbar with the
-static
switch and linking that file together with the remaining objectfiles to create the dynamic object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…