Error while loading shared libraries error solution in Linux

  By default, the compiler will only use the library files in the two directories /lib and /usr/lib. Usually, when installing from a source package, if --prefix is ​​not specified, the library will be installed in /usr/local/ lib directory; when the running program needs to link the dynamic library, it will prompt that the relevant .so library cannot be found, and an error will be reported. That is to say, the /usr/local/lib directory is not in the default library search directory of the system, and the directory needs to be added.

  1. First open the /etc/ld.so.conf file

  2. Add the directory where the dynamic library file is located: execute vi /etc/ld.so.conf, and add "/usr/local/lib" under "include ld.so.conf.d/*.conf".

  3. After saving, execute: /sbin/ldconfig -v on the command line terminal; its function is to cache the library files under the path listed in the file /etc/ld.so.conf to /etc/ld.so.cache to For use, so when some library files are installed, or /etc/ld.so.conf is modified to add a new search path for the library, you need to run ldconfig to make all library files cached to the file /etc/ld.so .cache, if you don't do it, you may not find the library you just installed.

  After the above three steps, the problem of "error while loading shared libraries" can usually be solved.

  If the above error is still prompted when running the application, it is necessary to confirm whether the current user does not have readable permissions in the library directory. The problem I encountered is that I copied some .so dynamic libraries from other machines, and then put them in /usr/local/lib with root permissions (normal users do not have write permissions to this directory), and then switched users to run the program When the .so library is not found, I always thought that there was a problem with my configuration. The result was because of permissions. Those .so files that I added to /usr/local/lib with root permissions are for ordinary users. There is no access rights, so when running the program as a normal user, when the .so library needs to be linked, it cannot be found in /usr/local/lib.

  In fact, for the .so library files compiled and generated by ordinary users, it is better to add the path of these .so library files to the LD_LIBRARY_PATH variable in ~/.bash_profile with the export command, and LD_LIBRARY_PATH is the program running needs to be linked. A directory that will be searched when the so library is found. ~/.bash_profile is a file that will be read when logging in or opening a shell. In this way, every time a user logs in, the path of these .so library files will be written into LD_LIBRARY_PATH, so that you can Use these .so library files normally.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324689362&siteId=291194637