且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

加载共享库时出现 Linux 错误:无法打开共享对象文件:没有这样的文件或目录

更新时间:2021-12-13 07:55:37

更新
虽然我在下面写的是关于共享库的一般答案,但我认为这些消息的最常见原因是因为您已经安装了一个包,但没有安装 -dev 版本的那个包裹.

好吧,这不是在说谎 - 该列表中没有 libpthread_rt.so.1.您可能需要重新配置并重新构建它,使其依赖于您拥有的库,或者安装任何提供 libpthread_rt.so.1 的东西.

Well, it's not lying - there is no libpthread_rt.so.1 in that listing. You probably need to re-configure and re-build it so that it depends on the library you have, or install whatever provides libpthread_rt.so.1.

一般来说,.so 后面的数字是版本号,你经常会发现它们是相互的符号链接,所以如果你有 libfoo.so 的 1.1 版本,你就会有一个真正的文件 libfoo.so.1.0,以及指向 libfoo.so.1.0 的符号链接 foo.so 和 foo.so.1.如果您安装 1.1 版本而不删除另一个版本,您将拥有一个 libfoo.so.1.1,并且 libfoo.so.1 和 libfoo.so 现在将指向新版本,但任何需要该确切版本的代码都可以使用 libfoo.so.1.0 文件.仅依赖版本 1 API,但不关心它是 1.0 还是 1.1 的代码将指定 libfoo.so.1.正如 orip 在评论中指出的那样,这很好解释 此处.

Generally, the numbers after the .so are version numbers, and you'll often find that they are symlinks to each other, so if you have version 1.1 of libfoo.so, you'll have a real file libfoo.so.1.0, and symlinks foo.so and foo.so.1 pointing to the libfoo.so.1.0. And if you install version 1.1 without removing the other one, you'll have a libfoo.so.1.1, and libfoo.so.1 and libfoo.so will now point to the new one, but any code that requires that exact version can use the libfoo.so.1.0 file. Code that just relies on the version 1 API, but doesn't care if it's 1.0 or 1.1 will specify libfoo.so.1. As orip pointed out in the comments, this is explained well at here.

在您的情况下,您可能libpthread_rt.so.1 符号链接到libpthread_rt.so.但是,不能保证它不会破坏您的代码并吃掉您的电视晚餐.

In your case, you might get away with symlinking libpthread_rt.so.1 to libpthread_rt.so. No guarantees that it won't break your code and eat your TV dinners, though.