Re: How to force static linking of some libs when using -shared?
Yves Arrouye writes:
> I'm building a .so file for a package, which uses a library I would like
> to link statically in the .so file. I currently use something like
> cc -shared *.o /usr/lib/libsomelib.a -o name.so
> Is there a shorter way? If I use -static -lsomelib it does not work...
You can sprinkle '-Wl,-Bstatic' and '-Wl,-Bdynamic' into you link
command line to force following libraries to be static or shared.
However, you really don't want to link one library that isn't compiled
with -fpic staticly into another shared library. Doing so will result
in a very memory inefficient library because the required fixups will
dirty most of the pages at load time.
> On the other hand, when I build without needing to statically link, I do
> cc -shared *.o -lsomelib -o name.so
> I think the -lsomelib is not useful since there's no link phase. Can I
> remove it?
Yes, but leaving it in is usally a good thing. The reason is that it
makes it obvious which other libraries are needed and less likely a
user will link with the wrong library.
David Engel Optical Data Systems, Inc.
email@example.com 1101 E. Arapaho Road
(214) 234-6400 Richardson, TX 75081