/usr/local/lib 中未找到共享库
我不明白。我通常将第三方软件安装到 /usr/local 中,因此库被安装到 /usr/local/lib 中,并且链接到这些库时从来没有出现过问题。但现在它突然不再起作用:
$ 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
时它就起作用了,但我以前从未使用过它。无需添加-I/usr/local/include
即可找到/usr/local/include中的头文件。
我使用的是 Debian GNU/Linux 6 (Squeeze),它在 /etc/ld.so.conf.d/libc.conf 中有一个 /usr/local/lib 条目em> 默认情况下,ldconfig 缓存知道我正在尝试使用的库:
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 默认搜索哪些库路径?也许那里出了什么问题。
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
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
.
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gcc -print-search-dirs 会告诉您编译器检查的路径。 /usr/local/lib 根本不在其中,因此您的编译时链接器(在本例中是来自 binutils 的新黄金 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/include 但不包括 /usr/local/lib
从环境变量上的 GCC 地图
并
尝试“printenv”来查看您设置的内容
This is probably an issue of environment variables - you have something set that's including /usr/local/include but not /usr/local/lib
From the GCC mapage on environment variables
and
try "printenv" to see what you have set