Skip to Content

Loading custom shared libraries in Linux

This post shows how to enforce loading custom shared libraries for a given executable on a Linux system.

It turns out that even playing computer games on Linux can sometimes teach us something useful. The other day, an attempt to run Nuclear Throne on my Arch Linux system produced the following error message.

$ ./runner 
./runner: error while loading shared libraries: cannot open shared object file: No such file or directory

A quick investigation reveals that the missing shared library belongs to the openssl package which was apparently upgraded to a newer version.

$ pacman -Qo /usr/lib/
/usr/lib/ is owned by openssl 1.1.0.e-1

The executable runner we are trying to run depends on version 1.0.0 of openssl. This can be easly seen from the output of the ldd command:

$ ldd runner (0xf7726000) => /usr/lib32/ (0xf755e000)
[...] => not found => not found

Obviously, it wouldn’t be wise to downgrade the openssl package. However, it is possible to provide the shared library loader with a list of .so files using the LD_PRELOAD variable.

In my case this simple call solves the problem:

LD_PRELOAD=/path/to/ ./runner

The LD_PRELOAD list must contain absolute paths to the relevant .so files since the original runner executable can call another executable sitting in some directory different from the current.