distroproof

How to fix "error while loading shared libraries"

Your program needs a shared library that the system's loader cannot find. Either it is not installed, it has a different version, or it sits outside the search path.

./mytool: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

Find everything that is missing

The error names only the first missing library. Use ldd to see them all, but only on binaries you trust, because it can run code from the file:

ldd ./mytool | grep "not found"

Find the package that provides it

SystemCommand
Debian, Ubuntuapt-file search libssl.so.3
Fedora, AlmaLinux, Rockydnf provides '*/libssl.so.3'
Alpineapk search so:libssl.so.3
Archpacman -F libssl.so.3

Package names differ between systems, so a dependency list written for one distribution rarely works on another. apt-file and pacman -F need their file databases updated first.

If the library is installed but not found

It may be outside the loader's search path, for example in /usr/local/lib or /opt. Add the directory to a file in /etc/ld.so.conf.d/ and run:

sudo ldconfig

If you ship the software

  1. Declare dependencies in your .deb or .rpm package so the package manager installs them.
  2. Link statically when the library allows it, so there is nothing to find at run time.
  3. Bundle the library next to your binary and set an rpath with $ORIGIN. You then own its security updates.