c++ - How can I link dynamic library depending on another dynamic library? -


i make program using dynamic library, libexample.so. dynamic library depends on dynamic library, libtool.so.

it looks linker succeeded linking libexample.so because of message gcc.

building target: libexample.so invoking: gcc c++ linker g++ -l/home/takehiro/documents/documents/code/lib/tool -shared -o "libexample.so"  ./classes/example.o ./classes/example_template.o ./classes/example_test.o ./classes/impl.o   -ltool finished building target: libexample.so  cp libexample.so /home/takehiro/documents/documents/code/lib/example 

however, failed link libtool.so.

ldd /home/takehiro/documents/documents/code/lib/example/libexample.so      ...     libtool.so => not found     ... 

i checked existence of libtool.so under /home/takehiro/documents/documents/code/lib/tool pointed -l optoin @ above linker by

ls /home/takehiro/documents/documents/code/lib/tool  libtool.so 

this first time use dynamic library depending dynamic library. so confused. normal or malfunction? why cannot link them? have suggestion or solution me? glad it. thank much.

all -l option tell linker shared library is, @ link time.

this not have effect on runtime loader searches shared libraries. that's why shared library fails loaded @ runtime.

you need pass -rpath option linker, when you're linking shared library, in order set rpath attribute on shared library, specifies dependencies searched for. like

g++ -l/home/takehiro/documents/documents/code/lib/tool \     -wl,-rpath=/home/takehiro/documents/documents/code/lib/tool \     ... remaining options 

Comments