Unable to load dynamic library under Linux
When the following abnormal situation occurs
./test: error while loading shared libraries: libmfs_open.so: cannot open shared object file: No such file or directory
If the path of the dynamic library is (/ usr / cluster /. Share / LIB)
terms of settlement:
Method 1: add the path to the / etc / ld.so.conf file, VI / etc / ld.so.conf
Add content below
include ld.so.conf.d/*.conf /usr/cluster/.share/lib
Method 2. Input at the terminal:
Method 3. Modify the / etc / profile file
export MPI_HOME=/usr/cluster export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MPI_HOME/.share/lib
Execute source / etc / profile on the terminal to make the configuration file effective
Solution to the failure of loading dynamic library when program is running
The error message is as follows:
error while loading shared libraries: libjson.so.0: cannot open shared object file: No such file or directory
There are generally two reasons. One is that the operating system does not contain the shared library (LIB *. So. * file) or the version of the shared library is incorrect. The solution is to download the installation again.
Another reason is that the shared library has been installed, but when executing the program that needs to call the shared library, the program cannot find the shared library file according to the default shared library path. The solution is as follows:
If the shared library file is installed in the / lib or / usr / lib directory, execute the ldconfig command.
The purpose of the ldconfig command is to search the directory listed in the default search directory (B and / usrb) and the dynamic library configuration file / etc / ld.so.conf to find the shared dynamic link library (such as lib *. So *), and then create the connection and cache files required by the dynamic loader (LD. So). The default cache file is / etc / ld.so.cache, which saves the name of the dynamic link library that has been arranged List of characters.
If the shared library file is installed in / usr / local / lib (generally open-source shared libraries will be installed in this directory) or other directories other than / lib or / usr / lib, the new shared library directory should be added to the shared library configuration file / etc / ld.so.conf before executing the ldconfig command, as follows:
# cat /etc/ld.so.conf include ld.so.conf.d/*.conf # echo "/usr/local/lib" >> /etc/ld.so.conf # ldconfig
Or create a new file with the suffix of. Conf in the directory / etc / ld.so.conf.d /. Add the directory where the library file is located. Then execute ldconfig to update the / etc / ld.so.cache file.
If the shared library file is installed in a directory other than / lib or / usr / lib, but you do not want to add the shared library path to the / etc / ld.so.conf file (or you do not have permission to add the path). You can export a global variable
LD_LIBRARY_PATH, and then when you run the program, you will find a shared library in a directory.
LD ﹣ library ﹣ path means to tell the loader in which directory the shared library can be found. You can set multiple search directories separated by colons. For example, if you have installed a MySQL to / usr / local / MySQL directory, and a large number of library files are under / usr / local / MySQL / lib, you can add the following statements to. Bashrc or. Bash ﹣ profile or shell:
Generally speaking, this is only a temporary solution, which is used when there is no permission or temporary need
If the library file required by the program is lower than the version of the library file currently existing in the system, you can make a link. For example:
error while loading shared libraries: libncurses.so.4: cannot open shared object file: No such file or directory ls /usr/lib/libncu* /usr/lib/libncurses.a /usr/lib/libncurses.so.5 /usr/lib/libncurses.so /usr/lib/libncurses.so.5.3
It can be seen that although there is no libncurses. So. 4, there is libncurses. So. 5, which is downward compatible
Just build a link
ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4
The above is the whole content of this article. I hope that the content of this article has some reference learning value for your study or work. Thank you for your support for developepaer. If you want to know more about it, please check the relevant links below