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

本文介绍如何编译和使用开源计算机视觉库VLFeat,并详细解释了如何将自定义库目录添加到ldconfig缓存中,确保程序可以正确加载共享库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值