How to specify shared object path in Linux

By , last updated November 22, 2019

If you’re on a system as a user and with no means of installing custom libraries or updating libraries for your custom program, you can load your own libraries with this simple command.

$ ./executable
./executable: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

Use ldd to find out what missing libraries you have:

$ ldd executable
        linux-gate.so.1 =>  (0xa942d000)
        libncursesw.so.5 => /lib/libncursesw.so.5 (0xa93e9000)
        libcurl.so.4 => not found
        librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xa93df000)
        libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8 (0xa939d000)
        libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xa9399000)
        libz.so.1 => /usr/lib/libz.so.1 (0xa9384000)
        libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xa9241000)
        libsigc-2.0.so.0 => /usr/lib/libsigc-2.0.so.0 (0xa923b000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xa9148000)
        libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xa9123000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xa9118000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xa8fc9000)
        libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xa8fb0000)
        /lib/ld-linux.so.2 (0xa942e000)

Copy over your libcurl.so.4 to the system and invoke your custom executable with:

$ LD_PRELOAD=./libcurl.so.4:./libexecutable.so.11 ./executable

Separate different libraries with a colon (:).