找不到/usr/local/lib中的共享库 [英] Shared library in /usr/local/lib not found

查看:788
本文介绍了找不到/usr/local/lib中的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白.我通常将第三方软件安装到/usr/local 中,因此将库安装到/usr/local/lib中,并且从未遇到链接到这些库的问题.但是现在突然不起作用了:

I don't get it. I usually install third party software into /usr/local so libraries are installed into /usr/local/lib and never had problems linking to these libraries. But now it suddenly no longer works:

$ gcc -lkaytils -o test test.c
/usr/bin/ld.gold.real: error: cannot find -lkaytils
/usr/bin/ld.gold.real: /tmp/ccXwCkYk.o: in function main:test.c(.text+0x15):
error: undefined reference to 'strCreate'
collect2: ld returned 1 exit status

当我添加参数-L/usr/local/lib时,它起作用了,但是我以前从未使用过它.找不到/usr/local/include 中的头文件,而无需添加-I/usr/local/include.

When I add the parameter -L/usr/local/lib than it works but I never had to use this before. Header files in /usr/local/include are found without adding -I/usr/local/include.

我正在使用Debian GNU/Linux 6(Squeeze),它在/etc/ld.so.conf.d/libc中具有/usr/local/lib 的条目. conf ,并且ldconfig缓存知道我要使用的库:

I'm using Debian GNU/Linux 6 (Squeeze) which has an entry for /usr/local/lib in /etc/ld.so.conf.d/libc.conf by default and the ldconfig cache knows the library I'm trying to use:

k@vincent:~$ ldconfig -p | grep kaytils
        libkaytils.so.0 (libc6,x86-64) => /usr/local/lib/libkaytils.so.0
        libkaytils.so (libc6,x86-64) => /usr/local/lib/libkaytils.so

那么这里到底发生了什么?默认情况下,我在哪里可以查看gcc搜索哪些库路径?那里可能有问题.

So what the heck is going on here? Where can I check which library paths are searched by gcc by default? Maybe something is wrong there.

推荐答案

gcc -print-search-dirs将告诉您编译器检查的路径. /usr/local/lib根本不在其中,因此您的编译时链接程序(在本例中为binutils的新Gold ld)找不到该库,而动态库(ld-linux.so)将读取由ldconfig).大概您之前完成的构建在必要时在其makefile中添加了-L/usr/local/lib(通常由./configure脚本完成),或者您已经安装了二进制文件.

gcc -print-search-dirs will tell you what path the compiler checks. /usr/local/lib is simply not among them, so your compile time linker (in this case the new gold ld from binutils) doesn't find the library while the dynamic one (ld-linux.so which reads the cache written by ldconfig) does. Presumably the builds you've done previously added -L/usr/local/lib as necessary in their makefiles (usually done by a ./configure script), or you installed binaries.

这篇关于找不到/usr/local/lib中的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆