Error while loading shared libraries:xxx.so.x "causes and workarounds for" errors

Source: Internet
Author: User
Tags in python

Small knitting quickly under the environment of Linux crazy, a few days ago changed a bit Caffe, who knows the disaster. Run the program under Caffe, you will be prompted: Error while loading shared Libraries:libprotobuf.so.8:cannot open Shared object file:no such file or D Irectory error.


The mistake is obviously that Caffe can't find the dependency library. And then he did a bit of work on it:

(1) Find the location of the dependent file libprotobuf.so.8, the file address is:/home/dell/local_install/lib

(2) View Caffe's environment Profile Makefile.config, and whether the file address is included in the BASHRC file

The result let small make up the glasses, obviously the configuration file contains the address of the dependent file, but at run time can not find. The little part really has no words.

Until yesterday, the small series has been using temporary methods to solve the problem, but now the small series found a permanent solution.

Workaround:

1, Temporary solution:

Each time Caffe is run, it is included in the dependent file.

CD Caffe
export ld_library_path= $LD _library_path:/home/dell/local_install/lib

This way, the Caffe can run normally.

Although Caffe works, you will still be prompted when you import Caffe in Python code: Error while loading shared Libraries:libprotobuf.so.8:cannot open Sha Red object File:no such file or directory error. Therefore, it is better to eradicate this hidden danger.


2, Permanent solution:

To add the new Shared library directory to the shared library profile/etc/ld.so.conf, execute the following command:

# cat/etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >>/etc/ld.so.conf
# Ldconfig

When writing a Lib path to a file, try to write it to the file using a command. Small series originally through the Gedit open the file, and then add content to the file, it may be a format error, after the addition of no use, so when the environment variable configuration, try to use the command to modify the configuration file.


The following is the content of the blog post (http://blog.csdn.net/sahusoft/article/details/7388617):

In general, when we execute some external programs under Linux, we may be prompted to find errors in the shared library, such as:



Tmux:error while loading shared libraries:libevent-1.4.so.2: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 shared library version is not correct, in this case, go to the Internet download and install it.

Another reason is that you have installed the shared library, but when you execute a program that calls the shared library, the program cannot find the shared library file by default shared library path.

Therefore, after installing the shared library, you should pay attention to the shared library path setting problem as follows:

1) If the shared library file is installed in the/lib or/usr/lib directory, then you need to execute the ldconfig command

The purpose of the Ldconfig command is to search for a shareable dynamic-link library (in the form of lib*.so*) in the default search directory (/lib and/usr/lib) and the directory listed in the dynamic library configuration file/etc/ld.so.conf, creating a dynamic Loader program ( ld.so) The required connection and cache files. The cache file defaults to/etc/ld.so.cache, which holds a list of queued dynamic-link library names.

2) If the shared library file is installed in/usr/local/lib (many open source shared libraries will be installed in this directory) or other "non-/lib or/usr/lib" directories, then the new Shared library directory will be added to the shared library configuration file before the Ldconfig command is executed/etc/ Ld.so.conf, the following:

# 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 file is installed in a different "non-/lib or/usr/lib" directory, but does not want to add the path in the/etc/ld.so.conf (or there is no permission to add the path). That can export a global variable ld_library_path, and then run the program will go to this directory to find the shared library.

Ld_library_path means to tell loader which directories can be found in the shared library. You can set up multiple search directories separated by colons. For example, install a MySQL into the/usr/local/mysql directory, where there are a lot of library files under/usr/local/mysql/lib, you can add the following statements in the. BASHRC or. Bash_profile or shell:

Export Ld_library_path=/usr/local/mysql/lib: $LD _library_path

In general, this is a temporary solution that is used when there is no authority or temporary need.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.