1

If I invoke the following command:

ldd mylib.so

this then yields something along the lines of:

libopencv_features2d.so.4.1 => /usr/local/lib/libopencv_features2d.so.4.1 (0x00007f83dee6b000)

If I copy /usr/local/lib/libopencv_features2d.so.4.1 into my current working directory, I would then expect ldd to show => ./libopencv_features2d.so.4.1 (0x00007f83dee6b000)

Instead, it still resolves it to /usr/local/lib. Why is that? And how do system dependencies like this get resolved? Is there also a way to influence the way dependencies are resolved? Can I force it to resolve it to my local directory?

3

The dynamic linker looks for libraries in a variety of places, but those don’t include the current directory by default. On Linux, the list is

  • the paths defined in the binary’s rpath, if any;
  • the paths listed in LD_LIBRARY_PATH, if any;
  • the paths defined in the binary’s runpath, if any;
  • the libraries known in /etc/ld.so.cache;
  • the system’s library paths (/usr/lib etc.).

The link above provides more detail.

You can influence the way dependencies are resolved by exporting LD_LIBRARY_PATH; specifically in your case:

export LD_LIBRARY_PATH=.

(Don’t leave it set to that value.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.