程序是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                                 

.1是文件名的最后部分吗?这到底是什么意思?


当前回答

更新 虽然我下面所写的是关于共享库的一般答案,但我认为这类消息最常见的原因是因为您安装了一个包,但没有安装该包的-dev版本。


好吧,这不是撒谎——没有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 orip pointed out in the comments, this is explained well at here.

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

其他回答

由于系统无法引用提到的库文件而发生错误。采取以下步骤:

执行locate libpthread_rt.so。1将列出所有具有该名称的文件的路径。假设路径是/home/user/ loco。 拷贝路径,执行cd home/USERNAME命令。将USERNAME替换为要运行该文件的当前活动用户的名称。 运行vi .bash_profile,在LD_LIBRARY_PATH参数的末尾,就在.之前,添加一行/lib://home/usr/loc:..保存文件。 关闭终端并重新启动应用程序。它应该运行。

想要添加的内容是,如果库位于非标准路径中,请在路径后面运行ldconfig。

例如,我必须跑:

sudo ldconfig /opt/intel/oneapi/mkl/2021.2.0/lib/intel64

在Intel MKL上编译R

这里有一些你可以尝试的解决方案:

LDCONFIG

正如AbiusX指出的:如果您刚刚安装了库,那么您可能只需要运行ldconfig。

sudo ldconfig

Ldconfig创建必要的链接和到最近的缓存 在命令中指定的目录中找到的共享库 在/etc/ld.so.conf文件中,在受信任的目录中 (/lib和/usr/lib)。

通常您的包管理器会在安装新库时处理这个问题,但并非总是如此,即使这不是您的问题,运行ldconfig也无妨。

开发包或版本错误

如果这不起作用,我也会检查Paul的建议,并寻找一个“-dev”版本的库。许多库被分为开发包和非开发包。你可以使用这个命令来查找它:

apt-cache search <libraryname>

如果您只是安装了错误的库版本,这也会有所帮助。有些库同时以不同的版本发布,例如Python。

图书馆的位置

如果您确定安装了正确的包,而ldconfig没有找到它,那么它可能只是在一个非标准目录中。默认情况下,ldconfig会在/lib、/usr/lib和/etc/ld.so.conf和$LD_LIBRARY_PATH目录中查找。如果你的库在其他地方,你可以在/etc/ld.so.conf中自己的行中添加目录,将库的路径附加到$LD_LIBRARY_PATH,或者将库移动到/usr/lib.然后执行ldconfig命令。

要找到图书馆的位置,试试这个:

sudo find / -iname *libraryname*.so*

(用你的库名替换libraryname)

如果您选择$LD_LIBRARY_PATH路径,则需要将其放到~/中。Bashrc文件,以便每次登录时运行:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/library

我使用Ubuntu 18.04

安装相应的-dev包对我来说很有效,

sudo apt install libgconf2-dev

在安装上面的包之前,我得到了以下错误:

turtl: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory

更新 虽然我下面所写的是关于共享库的一般答案,但我认为这类消息最常见的原因是因为您安装了一个包,但没有安装该包的-dev版本。


好吧,这不是撒谎——没有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 orip pointed out in the comments, this is explained well at here.

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