Linux LD_LIBRARY_PATH, rpath, and ld.so.conf (in that order)

I see a lot of people make life a lot more complicated for themselves than they need to because they don’t really understand how dynamically linked libraries work.

Let’s assume for the moment that you understand the pros/cons of static vs dynamic linking and a shared library is appropriate.

How do you make sure your program is using the correct library of the correct version?

In short: man ld.so


You can inspect which libraries a program is loading with readelf

readelf -d $PROGRAM

The linker will search in the following order:

  1. LD_LIBRARY_PATH environment variable
  2. rpath (man ld search “-rpath”)
  3. /etc/ld.so.conf (ldconfig to update)

Written on July 30, 2016