程序是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是文件名的最后部分吗?这到底是什么意思?


当前回答

我有一个类似的错误,它没有修复给LD_LIBRARY_PATH ~/。bashrc。( 解决我的问题是通过添加.conf文件并加载它。 去终端,进入su。

gedit /etc/ld.so.conf.d/myapp.conf

在此文件中添加库路径并保存。(如:/usr/local/lib)。 需要执行以下命令激活path:

ldconfig

验证您的新库路径:

ldconfig -v | less

如果这显示了库文件,那么就可以开始了。

其他回答

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

例如,我必须跑:

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

在Intel MKL上编译R

更新 虽然我下面所写的是关于共享库的一般答案,但我认为这类消息最常见的原因是因为您安装了一个包,但没有安装该包的-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。不过,不能保证它不会破坏你的代码并吃掉你的电视晚餐。

您的库是一个动态库。 您需要告诉操作系统在运行时可以在哪里定位它。

为了做到这一点, 我们需要做这些简单的步骤:

Find where the library is placed if you don't know it. sudo find / -name the_name_of_the_file.so Check for the existence of the dynamic library path environment variable(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 We add the desired path, export it and try the application. 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: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ export LD_LIBRARY_PATH ./my_app

引用来源

linux.org参考页面解释了机制,但没有解释背后的动机:-(

为此,请参阅Sun Linker和图书馆指南

此外,请注意,“外部版本控制”在Linux上基本上已经过时了,因为符号版本控制(GNU扩展)允许您在单个库中呈现同一个函数的多个不兼容版本。这个扩展允许glibc拥有相同的外部版本:libc.so。过去10年有6个。

我在Linux x86上使用Eclipse CDT运行应用程序时遇到了这个错误。 要解决这个问题:

在Eclipse中: 执行命令as ->执行配置命令->环境 设置路径 LD_LIBRARY_PATH = / my_lib_directory_path