When you run a program and see an error indicating that a library file or dynamic library file is missing or not loaded, it usually means your system is missing a required library.
For example, when executing octave, you might see:
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
Referenced from: /usr/local/Cellar/octave/4.4.1_4/bin/octave-cli-4.4.1
Reason: image not found
This message indicates that the file libreadline.7.dylib was not found.
There are two common reasons for this problem:
1. The Library Is Not Installed
To check if the library is installed, search for files related to libreadline:
updatedb
locate libreadline
You may find several files, such as:
/usr/lib/libreadline.dylib
/usr/local/Cellar/readline/7.0.5/lib/libreadline.7.0.dylib
/usr/local/Cellar/readline/7.0.5/lib/libreadline.7.dylib
/usr/local/Cellar/readline/8.0.1/lib/libreadline.8.dylib
...
If you find relevant files, the library is installed. If not, install it using your package manager (e.g., apt, yum, or brew).
2. Version Mismatch
Sometimes, the required version (e.g., version 7) is missing, but another version (e.g., version 8) is present. In this case, you can create a symbolic link from the existing version to the required version.
Navigate to the library directory:
$ cd /usr/local/opt/readline/lib
$ ls
libreadline.8.0.dylib
Create a symbolic link:
ln -s libreadline.8.0.dylib libreadline.7.dylib
Now, try running your program again:
$ octave
GNU Octave, version 4.4.1
...
If the program starts successfully, the issue is resolved.
Summary
When a library file is missing:
- Install the required library using your package manager.
- Copy the library from another system if available.
- Create a symbolic link from an existing version to the required version, and place it in the correct directory.
These steps should resolve most dynamic library not found errors on Linux systems.