Take the 2-minute tour ×

Is it possible to provide a shared library - which links against another shared library during its creation - transparent to the end user?

As an example of what I mean:

Shared Library Build

g++ ... `pkg-config gtk+-2.0 --cflags` ... `pkg-config gtk+-2.0 --libs`

Desired User Build

g++ file.cc -lfoo

Where libfoo.so.0 is the shared library.

I can only seem to get this to work if the user build includes the pkg-config gtk+-2.0 .... Is there a way, during the creation of the shared object, to allow the end user to not have to worry about the indirect libraries used within libfoo?

share|improve this question
is it possible that you are picking-up a static version of the gtk lib istead? If so, it will be required during the user link as well. Otherwise, if it truly is using the shared lib, it shouldn't be required at build time but WILL be required at runtime. –  Mike Ellery Jul 8 '11 at 18:04
add comment

1 Answer

up vote 3 down vote accepted

If you have a shared library libABC.so which links to libXYZ.so then,
while creating your libABC.so, you have to link with libXYZ.so

 ld --shared -o libABC.so -L. -lXYZ

While compiling the application,

gcc app.c -L. -lABC

don't forget to, export the library path

share|improve this answer
+1 you can set the DT_RPATH as well with -Wl,-rpath,. instead of relying on the LD_LIBRARY_PATH environmental variable. –  Sam Miller Jul 8 '11 at 20:28
add comment

Your Answer


