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: cannot open shared object file: No such file or directory

Use ldd to find out what missing libraries you have:

$ ldd executable =>  (0xa942d000) => /lib/ (0xa93e9000) => not found => /lib/tls/i686/cmov/ (0xa93df000) => /usr/lib/i686/cmov/ (0xa939d000) => /lib/tls/i686/cmov/ (0xa9399000) => /usr/lib/ (0xa9384000) => /usr/lib/i686/cmov/ (0xa9241000) => /usr/lib/ (0xa923b000) => /usr/lib/ (0xa9148000) => /lib/tls/i686/cmov/ (0xa9123000) => /lib/ (0xa9118000) => /lib/tls/i686/cmov/ (0xa8fc9000) => /lib/tls/i686/cmov/ (0xa8fb0000)
        /lib/ (0xa942e000)

Copy over your to the system and invoke your custom executable with:

$ LD_PRELOAD=./ ./executable

Separate different libraries with a colon (:).