加载共享库时出现 Linux 错误:无法打开共享对象文件:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/480764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux error while loading shared libraries: cannot open shared object file: No such file or directory
提问by zaratustra
Program is part of the Xenomai test suite, cross-compiled from Linux PC into Linux+Xenomai ARM toolchain.
程序是 Xenomai 测试套件的一部分,从 Linux PC 交叉编译成 Linux+Xenomai ARM 工具链。
# echo $LD_LIBRARY_PATH
/lib
# ls /lib
ld-2.3.3.so libdl-2.3.3.so libpthread-0.10.so
ld-linux.so.2 libdl.so.2 libpthread.so.0
libc-2.3.3.so libgcc_s.so libpthread_rt.so
libc.so.6 libgcc_s.so.1 libstdc++.so.6
libcrypt-2.3.3.so libm-2.3.3.so libstdc++.so.6.0.9
libcrypt.so.1 libm.so.6
# ./clocktest
./clocktest: error while loading shared libraries: libpthread_rt.so.1: cannot open shared object file: No such file or directory
Edit:OK I didn't notice the .1 at the end was part of the filename. What does that mean anyway?
编辑:好的,我没有注意到最后的 .1 是文件名的一部分。这到底是什么意思?
采纳答案by Paul Tomblin
Update
While what I write below is true as a general answer about shared libraries, I think the most frequent cause of these sorts of message is because you've installed a package, but not installed the "-dev" version of that package.
更新
虽然我在下面写的内容是关于共享库的一般答案,但我认为这些消息的最常见原因是因为您已经安装了一个包,但没有安装该包的“-dev”版本。
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
.
嗯,这不是在说谎 -libpthread_rt.so.1
该列表中没有。您可能需要重新配置并重新构建它,以便它取决于您拥有的库,或者安装任何提供libpthread_rt.so.1
.
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 orippointed out in the comments, this is explained well at http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html.
一般来说,.so后面的数字是版本号,你经常会发现它们是相互的符号链接,所以如果你有1.1版的libfoo.so,你就会有一个真实的文件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在评论中指出的,这在http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html 中有很好的解释。
In your case, you mightget 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.
在您的情况下,您可能会通过符号链接libpthread_rt.so.1
到libpthread_rt.so
. 但是,不能保证它不会破坏您的代码并吃掉您的电视晚餐。
回答by Employed Russian
The linux.org reference page explains the mechanics, but doesn't explain any of the motivation behind it :-(
linux.org 参考页面解释了机制,但没有解释其背后的任何动机:-(
For that, see Sun Linker and Libraries Guide
为此,请参阅Sun 链接器和库指南
In addition, note that "external versioning" is largely obsolete on Linux, because symbol versioning (a GNU extension) allows you to have multiple incompatible versions of the same function to be present in a single library. This extension allowed glibc to have the same external version: libc.so.6
for the last 10 years.
此外,请注意“外部版本控制”在 Linux 上基本上已经过时,因为符号版本控制(GNU 扩展)允许您在单个库中存在同一函数的多个不兼容版本。此扩展允许 glibc 具有相同的外部版本:libc.so.6
过去 10 年。
回答by zajac.m2
try installing sudo lib32z1
尝试安装 sudo lib32z1
sudo apt-get install lib32z1
须藤 apt-get 安装 lib32z1
回答by XOR
Your library is a dynamic library. You need to tell the operating system where it can locate it at runtime.
您的库是一个动态库。您需要告诉操作系统它可以在运行时在哪里找到它。
To do so, we will need to do those easy steps:
为此,我们需要执行以下简单步骤:
(1 ) Find where the library is placed if you don't know it.
(1) 如果不知道,请查找库的放置位置。
sudo find / -name the_name_of_the_file.so
(2) Check for the existence of the dynamic library path environment variable(LD_LIBRARY_PATH
)
(2) 检查动态库路径环境变量是否存在( LD_LIBRARY_PATH
)
$ echo $LD_LIBRARY_PATH
if there is nothing to be displayed, add a default path value (or not if you wish to)
如果没有要显示的内容,请添加默认路径值(如果您愿意,也可以不添加)
$ LD_LIBRARY_PATH=/usr/local/lib
(3) We add the desire path, export it and try the application.
(3) 我们添加想要的路径,将其导出并尝试应用程序。
Note that the path should be the directory where the path.so.something
is.
So if path.so.something
is in /my_library/path.so.something
it should be :
请注意,路径应该是所在的目录path.so.something
。所以如果path.so.something
在/my_library/path.so.something
它应该是:
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/
$ export LD_LIBRARY_PATH
$ ./my_app
source : http://www.gnu.org/software/gsl/manual/html_node/Shared-Libraries.html
来源:http: //www.gnu.org/software/gsl/manual/html_node/Shared-Libraries.html
回答by Ankit Marothi
Try adding LD_LIBRARY_PATH
, which indicates search paths, to your ~/.bashrc
file
尝试将LD_LIBRARY_PATH
,表示搜索路径,添加到您的~/.bashrc
文件
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path_to_your_library
It works!
有用!
回答by amo
Here are a few solutions you can try:
您可以尝试以下几种解决方案:
ldconfig
配置文件
As AbiusX pointed out: If you have just now installed the library, you may simply need to run ldconfig.
正如 AbiusX 指出的那样:如果您刚刚安装了该库,您可能只需要运行ldconfig。
sudo ldconfig
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).
ldconfig 创建必要的链接并缓存到在命令行指定的目录、文件 /etc/ld.so.conf 和受信任的目录(/lib 和 /usr/lib)中找到的最新共享库。
Usually your package manager will take care of this when you install a new library, but not always, and it won't hurt to run ldconfig even if that is not your issue.
通常,当您安装新库时,您的包管理器会处理这个问题,但并非总是如此,即使这不是您的问题,运行 ldconfig 也不会受到伤害。
Dev package or wrong version
开发包或错误版本
If that doesn't work, I would also check out Paul's suggestionand look for a "-dev" version of the library. Many libraries are split into dev and non-dev packages. You can use this command to look for it:
如果这不起作用,我还会查看Paul 的建议并寻找该库的“-dev”版本。许多库分为开发包和非开发包。您可以使用此命令来查找它:
apt-cache search <libraryname>
This can also help if you simply have the wrong version of the library installed. Some libraries are published in different versions simultaneously, for example, Python.
如果您只是安装了错误版本的库,这也有帮助。一些库同时发布在不同的版本中,例如 Python。
Library location
图书馆位置
If you are sure that the right package is installed, and ldconfig didn't find it, it may just be in a nonstandard directory. By default, ldconfig looks in /lib
, /usr/lib
, and directories listed in /etc/ld.so.conf
and $LD_LIBRARY_PATH
. If your library is somewhere else, you can either add the directory on its own line in /etc/ld.so.conf
, append the library's path to $LD_LIBRARY_PATH
, or move the library into /usr/lib
. Then run ldconfig
.
如果您确定安装了正确的软件包,而 ldconfig 没有找到它,它可能只是在一个非标准目录中。默认情况下,看起来LDCONFIG中/lib
,/usr/lib
和目录中列出/etc/ld.so.conf
和$LD_LIBRARY_PATH
。如果你的库是在其他地方,你可以添加的目录在其自己的行/etc/ld.so.conf
,图书馆的路径追加到$LD_LIBRARY_PATH
,或图书馆迁入/usr/lib
。然后运行ldconfig
。
To find out where the library is, try this:
要找出库的位置,请尝试以下操作:
sudo find / -iname *libraryname*.so*
(Replace libraryname
with the name of your library)
(替换libraryname
为您图书馆的名称)
If you go the $LD_LIBRARY_PATH
route, you'll want to put that into your ~/.bashrc
file so it will run every time you log in:
如果你走这$LD_LIBRARY_PATH
条路线,你会想把它放到你的~/.bashrc
文件中,这样它就会在你每次登录时运行:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/library
回答by Bithin Alangot
I had the similar error, I could resolve it by giving,
我有类似的错误,我可以通过给出解决它,
sudo ldconfig -v
Hope this helps.
希望这可以帮助。
回答by jonny
All I had to do was run:
我所要做的就是运行:
sudo apt-get install libfontconfig1
I was in the folder located at /usr/lib/x86_64-linux-gnu
and it worked perfectly.
我在位于 的文件夹中/usr/lib/x86_64-linux-gnu
,它运行良好。
回答by ALM865
Another possible solution depending on your situation.
另一种可能的解决方案取决于您的情况。
If you know that libpthread_rt.so.1 is the same as libpthread_rt.so then you can create a symlink by:
如果您知道 libpthread_rt.so.1 与 libpthread_rt.so 相同,那么您可以通过以下方式创建符号链接:
ln -s /lib/libpthread_rt.so /lib/libpthread_rt.so.1
Then ls -l /lib
should now show the symlink and what it points to.
然后ls -l /lib
现在应该显示符号链接及其指向的内容。
回答by vipin nair
The error occurs as the system cannot refer to the library file mentioned. Take the following steps:
发生错误是因为系统无法引用提到的库文件。采取以下步骤:
- Running
locate libpthread_rt.so.1
will list the path of all the files with that name. Let's suppose a path is/home/user/loc
. - Copy the path and run
cd home/USERNAME
. Replace USERNAME with the name of the current active user with which you want to run the file. - Run
vi .bash_profile
and at the end of theLD_LIBRARY_PATH
parameter, just before.
, add the line/lib://home/usr/loc:.
. Save the file. - Close terminal and restart the application. It should run.
- 运行
locate libpthread_rt.so.1
将列出具有该名称的所有文件的路径。让我们假设一条路径是/home/user/loc
。 - 复制路径并运行
cd home/USERNAME
。将 USERNAME 替换为要用于运行文件的当前活动用户的名称。 - 运行
vi .bash_profile
并在LD_LIBRARY_PATH
参数的末尾,就在 之前.
,添加行/lib://home/usr/loc:.
。保存文件。 - 关闭终端并重新启动应用程序。它应该运行。