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
| System | Command |
|---|---|
| Debian, Ubuntu | apt-file search libssl.so.3 |
| Fedora, AlmaLinux, Rocky | dnf provides '*/libssl.so.3' |
| Alpine | apk search so:libssl.so.3 |
| Arch | pacman -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
- Declare dependencies in your
.debor.rpmpackage so the package manager installs them. - Link statically when the library allows it, so there is nothing to find at run time.
- Bundle the library next to your binary and set an rpath with
$ORIGIN. You then own its security updates.