> I am compiling a dynamic loadable library (*.so) under Unix (I'm working
> under Solaris, but I guess my question applies to other Unix versions also).
> This library requires other .so libraries to function. Now there are 2 ways
> I can deal with this:
> 1. Include the header files of the included library during compilation.
> Do _not_ include the included library during linking, or
> 2. Include the header files of the included library during compilation,
> _and_ include the included library during linking.
> Both of these work. When doing ldd on the 1st and the 2nd approach, I can
> see that in the 2nd case the included libraries are required.
In both cases the same libraries are required. The difference is whether ld
can determine which libraries are required from the shared object.
If you use the first case all libraries must be specified explicitly
when you link a program to your library. So the user of your library must
figure out which system libraries your shared library relies on.
In the second case your shared library contains enough information so that
the linker (ld) can resolve it's dependencies. So if I were to use your
library it would be sufficient for me to just link to your shared library.
IOW, I don't care what other libraries it depends on (assuming they are found
by the linker).
> Can anyone tell me the pros and cons of either method? What is the preferred
> way of doing this?
If you use ldd in /usr/lib you will see the many dependencies that exist.
I for one like not having to discover those dependencies each time I use
a system library.
Another argument is that a feature of shared objects is that they can provide
a 'plug in' capability. You can change a shared library and extend the
capability of a program without relinking. If I have a program that was no
linked to the libraries needed to use sockets but later wanted to replace
a shared object with one that uses sockets I can do that as long as the
shared object is linked against the required libraries. The runtime linker
determines that the socket related libraries are needed at runtime by
examining the shared libraries recursively.
Senior Software Engineer
Genetics Computer Group, a subsidiary of Pharmacopeia, Inc.