error while loading shared libraries xx

  • 2020-05-06 12:08:46
  • OfStack

In general, when we execute some external program under Linux, we may notice that the Shared library cannot be found, such as


tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory


Generally there are two reasons, one is that the operating system does not contain the Shared library (lib*

Another reason is that the Shared library is already 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.

So after installing the Shared library, pay attention to the Shared library path setting, as follows :

1) if the Shared library files are installed in the /lib or /usr/lib directory, then the ldconfig command

needs to be executed

ldconfig command USES, primarily in the default search directory (/ lib and/usr/lib) 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 *), To create dynamic loader (ld so) needed for the connections and the cache file. The cache file defaults to/etc/ld so. cache, this file has been sorted dynamic link library name list.

2) if the Shared library files installed to/usr/local lib (many open source Shared libraries 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

3) if the Shared library files installed to other "non/lib or/usr lib" directory,   but don't want to in/etc/ld so. conf china-canada path (or there is no permission to add path). It can export a global variable LD_LIBRARY_PATH, then run the program will go to the directory to find the Shared library.

LD_LIBRARY_PATH mean tell loader in which Shared library can be found in the directory. You can set multiple search directories, separated by a colon between these catalogs. Such as installed a mysql to/usr local/mysql directory, there are a lot of libraries in/usr local/mysql/lib below, You can add the following statement to.bashrc or.bash_profile or shell :

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.


Related articles: