Search code examples
linuxshared-librariesdynamic-linkinglibtool

Do permanent linking to other shared libraries


currently I'm creating a shared library "libmylib.so" using libtool with statements like this:

libtool --mode=compile g++ -Wall -fPIC -shared $(CFLAGS) $(LFLAGS) $(LSTATIC)
libtool --mode=link g++ -shared -export-symbols-regex beam_ -rpath /usr/lib -lotherlib

The library created with this depends on an other (non-static) library "libotherlib.so", that's why I'm using the statement "-lotherlib".

Now when I build an executable that links against libmylib.so something strange happens: I have to link against libotherlib.so again, means I have to add a statement "-lotherlib" for this executable too.

So it seems former linking of libotherlib.so when building libmylib.so does not to be persistent. But how can I change this? How can I build libmylib.so so that it implicitely knows about its dependency to shared library libotherlib.so?

Thanks!


Solution

  • The answer seems to be the same like for this question: Link a static library to a shared one during build?

    Big difference: when shared objects are specified for linking instead of static ones they are not included but the generated shared library remembers its dependnecy to these so's.