为什么通过将 /usr/lib 添加到 ld.so.conf 可以修复运行时未定义的符号?

发布于 2024-09-27 03:52:47 字数 381 浏览 8 评论 0原文

我在 Linux 中有一个案例,其中 gcc 和 ld 干净地构建了东西,但在运行时我得到了一个未定义的符号(对于 libxerces-c.so.28 中的某些东西),由我自己的共享库之一在运行我的程序时报告。

第一个假设是缓存已损坏,最近安装了 xerces,或类似的东西,所以我运行了 ldconfig。没有修好。但是将 /usr/lib 添加到 ld.so.conf 然后运行 ​​ldconfig 确实修复了它。

我的理解是/lib、/usr/lib,也许运行时动态链接器总是会搜索其他一两个位置。

??

(唯一不寻常的是,这是一个使用 jni 访问应用程序共享库的 java 程序。话又说回来,如果有什么合理的话,我应该在这个应用程序的过去 N 年里随时看到这个错误。)

I've got a case in linux where gcc and ld build things cleanly, but at runtime I get an undefined symbol (for something in libxerces-c.so.28), reported by one of my own shared libraries, when running my program.

First assumption was cache was broken, xerces recently installed, or something similar, so I ran ldconfig. Didn't fix it. But adding /usr/lib to ld.so.conf and then running ldconfig did fix it.

My understanding is /lib, /usr/lib, and perhaps one or two other spots are always searched by the run-time dynamic linker.

??

(The only thing out of the ordinary is this is a java program using jni to access application shared-libraries. Then again, if it were anything rational I should have seen this error any time in the past N years of this application.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

各自安好 2024-10-04 03:52:47

在这种特殊情况下,该库位于 /usr/lib 中,但也位于另一个项目中(链接器首先找到该项目)。它一定是一个坏的/不完整的,因为它显然缺少一个符号。

我通过运行我的程序来解决这个问题,因为

LD_DEBUG=libs ./a.out

这让我看到链接器挖掘不同的搜索路径,我看到它抓住了错误的路径。

哦 - 并且显式地将 /usr/lib 添加到 ld 配置中?这只是将 /usr/lib 放在搜索路径中比通常更早的位置,并且(运气好?)使 ld 在坏库之前找到好库。

In this particular case, the library was in /usr/lib, but also in with another project (and the linker was finding that one first). And it must have been a bad/incomplete one, since it was obviously missing a symbol.

I figured this out by running my program as

LD_DEBUG=libs ./a.out

That let me watch the linker dig through the different search paths, and I saw it grab the wrong one.

Oh - and explicitly adding /usr/lib to the ld configuration? That just put /usr/lib earlier in the search path than it normally would have been, and (luck?) made ld find the good library before the bad one.

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