Linux program runtime load dynamic library failure solution
- 2021-01-14 07:26:04
- OfStack
Unable to load dynamic libraries under Linux
When the following exception occurs
[./test: error while loading shared libraries: libmfs_open.so: cannot open shared object file: No such file or directory
]If the dynamic library path (/ usr cluster /. share/lib)
Solutions:
Method 1. In the/etc ld. so. Add path conf files, vi/etc/ld so. conf
Add the following content
include ld.so.conf.d/*.conf
/usr/cluster/.share/lib
Method 2. Enter at the terminal:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/cluster/.share/lib
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
The solution to the failure to load the dynamic library while the program is running
The error is as follows:
[error while loading shared libraries: libjson.so.0: cannot open shared object file: No such file or directory
]There are usually two reasons. One is that the shared library (lib*.so.* file) is not included in the operating system or the version of the shared library is wrong. The solution is to download and install again.
Another reason is that the shared library has been installed, but when executing a 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 files are installed in /lib or /usr/lib, execute the ldconfig command.
ldconfig command USES, primarily in the default search directory (b and/usrb) and dynamic library configuration file/etc/ld so. conf listed in the directory, search can be Shared out the dynamic link library (format such as lib *. so *), and then create a dynamic loader (ld. so) needed for the connection and the cache file. Cache file defaults to/etc/ld so. cache, this file has been sorted dynamic link library name list.
If the Shared library files installed to/usr/local lib (1 open source of Shared library will be installed in the directory) or other non/lib or/usr/lib directory, so before ldconfig command, but also add a new Shared library directory to a Shared library configuration file/etc/ld so. conf, as follows:
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
Or in/etc ld. so. conf. No new with the d/directory conf suffix file, add library files in the file's directory. Then execute ldconfig update/etc/ld so. cache file.
If the Shared library files installed by other than/lib or/usr lib directory, but don't want to in/etc/ld so. conf add Shared library file path (or no permission to add path). That can be export 1 global variable
LD_LIBRARY_PATH
", and then when the program runs it will look for a shared library in a directory.
The purpose of LD_LIBRARY_PATH is to tell loader which directories to find shared libraries in. Can set up multiple search directories, separated by a colon between these catalogs. Such as 1 mysql installed to/usr/local/mysql directory, there are a lot of libraries in/usr local/mysql/lib below, you can in. bashrc or. bash_profile or shell to join the following statement can be:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
Generally speaking, this is only a temporary solution, used when there is no permission or temporary need.
If your program needs a lower version of a library than the one currently available on your system, you can make a link. Such as:
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
libncurses.so.5 is compatible with libncurses.so.4 is not available
Just make a link
ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4
conclusion