link shared library against another shared library

Eljay Love-Jensen eljay@adobe.com
Thu Jul 24 20:51:00 GMT 2008


Hi qcp,

> I have a shared library A which uses shared library B, and an application P
> which relies on A.
> 
> I don't want to link P against A and B, but to link P against A only, and A
> against B (and somehow hide B to P)
> 
> How can I do ?
> 
> The shared libraries are generated with 'g++ -shared...'
> 
> Thanks for your answers

g++ -o P P.cpp -lA

That will make P directly dependent on libA.so, and not directly dependent
on libB.so (although it is indirectly dependent on libB.so, via libA.so).

You can use...  ldd P  ...to display the dependencies.  Depending on your
ldd, it may-or-may-not show indirect dependencies as well.  Check your
platform's "man ldd" for relevant flags.

HTH,
--Eljay



More information about the Gcc-help mailing list