1. 程式人生 > >error loading shared libraries: libvl.so 解決方案

error loading shared libraries: libvl.so 解決方案

轉自http://choorucode.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/

和http://choorucode.com/2014/02/11/how-to-compile-and-use-vlfeat/

How to compile and use VLFeat

VLFeat is an open source library that has implementations of computer vision algorithms such as HOG and SIFT. The source code is particularly well written and is easy to read and understand.

編譯

  • Download a stable version of the source code from here or get the latest source code from its Github repository here.

  • To compile, just type make.

  • For convenience, export an environment variable named VLROOT set to the directory of the VLFeat source code:

export VLROOT=/home/joe/vlfeat

使用

Here is a minimal piece of source code from its documentation:

extern "C"{
   #include <vl/generic.h>
}

int main()
{
    VL_PRINT("Hello world!");
    return 0;
}

While compiling code that uses VLFeat, remember to pass its include directory, its library directory and the library itself:

$ g++ foobar.cpp -I$VLROOT -L$VLROOT/bin/glnxa64/ -lvl

Finally, add the $VLROOT/bin/glnxa64 directory to the ldconfig cache as explained here. This enables your program to find and load the libvl.so shared library when it is executed. 

新增到ldconfig

How to add library directory to ldconfig cache

Problem

ldconfig is a program that is used to maintain the shared library cache. This cache is typically stored in the file /etc/ld.so.cache and is used by the system to map a shared library name to the location of the corresponding shared library file. This is used when a program is executed to find locations of shared libraries that need to be dynamically loaded and linked to the program. By default, the shared library files in /lib/usr/liband a few other standard directories are maintained in the cache by ldconfig.

A new program or library might be installed in a non-standard directory, for example in/opt/foobar/lib. Programs that need the shared libraries from this library might fail with this error when executed:

hello-world-program: error while loading shared libraries: libFoobar.so.1: cannot open shared object file: No such file or directory

The libFoobar.so.1 might be located in /opt/foobar/lib, but the system does not know this, so it cannot successfully load and execute the program.

Solution

To fix this problem, we need to add the library directory to the list used by ldconfig and run it again to rebuild its cache with the shared library files found in the new directory.

  • Open the /etc/ld.so.conf as sudo and add a new line with the library directory. In this case, we add /opt/foobar/lib.

  • Rerun ldconfig to rebuild the cache:

$ sudo ldconfig
  • Check if the shared library cache now includes the shared libraries from the new directory:
$ ldconfig -p

Your program should now execute without any errors :-)

Tried with: Ubuntu 12.04 LTS

Tried with: VLFeat 0.9.18 and Ubuntu 12.04 LTS