/usr/local/lib 中未找到共享库

发布于 2024-11-04 20:18:40 字数 925 浏览 0 评论 0原文

我不明白。我通常将第三方软件安装到 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-11-11 20:18:40

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.

断桥再见 2024-11-11 20:18:40

这可能是环境变量的问题 - 您设置了一些内容,其中包括 /usr/local/include 但不包括 /usr/local/lib

从环境变量上的 GCC 地图

       CPATH specifies a list of directories to be searched as if speci‐
       fied with -I, but after any paths given with -I options on the com‐
       mand line.  This environment variable is used regardless of which
       language is being preprocessed.

       The value of LIBRARY_PATH is a colon-separated list of directories,
       much like PATH.  When configured as a native compiler, GCC tries
       the directories thus specified when searching for special linker
       files, if it can’t find them using GCC_EXEC_PREFIX.  Linking using
       GCC also uses these directories when searching for ordinary
       libraries for the -l option (but directories specified with -L come
       first).

尝试“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

       CPATH specifies a list of directories to be searched as if speci‐
       fied with -I, but after any paths given with -I options on the com‐
       mand line.  This environment variable is used regardless of which
       language is being preprocessed.

and

       The value of LIBRARY_PATH is a colon-separated list of directories,
       much like PATH.  When configured as a native compiler, GCC tries
       the directories thus specified when searching for special linker
       files, if it can’t find them using GCC_EXEC_PREFIX.  Linking using
       GCC also uses these directories when searching for ordinary
       libraries for the -l option (but directories specified with -L come
       first).

try "printenv" to see what you have set

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文