Linux可执行文件执行时找不到共享库

42 篇文章 0 订阅
编译程序时使用了如下参数指定了链接库的位置,但是执行时提示无法加载共享库。

#gcc test.c -L /usr/local/rrdtool-1.2.30/lib -lrrd

现象:

error while loading libraries:librrd.so.2:cannot open shared object file:No such file or directory

解决方法:

使用ldd命令 查看编译生成的可执行文件发现:

#ldd a.out

命令输出结果:

librrd.so.2 => not found

修改/etc/ld.so.conf文件添加 目录——/usr/local/rrdtool-1.2.30/lib

执行如下命令:

#ldconfig

再次执行如下命令:

#ldd a.out

本身输出:

librrd.so.2 => /usr/local/rrdtool-1.2.30/lib/librrd.so.2



原理:

编译时确实是通过了,因为你编译时指定了编译时需要的有关该共享库的信息。

但是没有指定运行时(run time)所需要的信息;man一把ldconfig命令就知道原因了。

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache(/etc/ld.so.cache
) is used by the run-time linker, ld.so or ld-linux.so.

需要的动态来接库的目录路径,必须在/etc/ld.so.cache 文件中,而该文件是通过ld.so.conf指定的目录,以及信任目录(/lib and /usr/lib),使用ldconfig命令生成的。ldd命令也查看可执行文件所依赖的动态库信息时,也使用了/etc/ld.so.cache文件,因此在没有将所需要的动态库目录添加到ld.so.conf中且执行ldconfig时,会提示该库"not found"

from:http://blog.163.com/lyzaily@126/blog/static/42438837201222373118749/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值