Search code examples
gccld

ldd shows library not found for shared library dependency


I am using some -l flags along with a -L flag to specify some shared libraries as dependencies. However when I look at the resulting .so with ldd it shows that the libraries I linked with were not found. Here is what I am compiling with:

gcc -std=c99 -fPIC -shared -o lib/libmylib.so src/mylib.o -lmydep -L/path/to/libmydep.so

what I have found to work is if I set LD_LIBRARY_PATH to the path before compiling it is able to find the library for -ltest but despite my attempts I haven't been able to successfully set LD_LIBRARY_PATH from my Makefile so this isn't a viable solution for me.

EDIT:

I have tried exporting LD_LIBRARY_PATH with the following at the top of my Makefile:

... some var definitions ...
LD_LIBRARY_PATH = /path/to/libmydep.so
... some more var definitions ...
export ... some vars ... LD_LIBRARY_PATH

... make targets start here ...

Solution

  • I finally came across this question in which the answer provided by @schily worked for me.