Linux error while loading shared libraries: cannot

2020-01-22 18:45发布

Program is part of the Xenomai test suite, cross-compiled from Linux PC into Linux+Xenomai ARM toolchain.

# 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?

18条回答
不美不萌又怎样
2楼-- · 2020-01-22 19:07

I had the similar error, I could resolve it by giving,

sudo ldconfig -v

Hope this helps.

查看更多
男人必须洒脱
3楼-- · 2020-01-22 19:09

The linux.org reference page explains the mechanics, but doesn't explain any of the motivation behind it :-(

For that, see Sun Linker and Libraries Guide

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.

查看更多
三岁会撩人
4楼-- · 2020-01-22 19:10

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:

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.

查看更多
趁早两清
5楼-- · 2020-01-22 19:14

I had a similar error and it didn't fix with giving LD_LIBRARY_PATH in ~/.bashrc . What solved my issue is by adding .conf file and loading it. Go to terminal an be in su.

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

Add your library path in this file and save.(eg: /usr/local/lib). You must run the following command to activate path:

ldconfig

Verify Your New Library Path:

ldconfig -v | less

If this shows your library files, then you are good to go.

查看更多
可以哭但决不认输i
6楼-- · 2020-01-22 19:17

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.

sudo find / -name the_name_of_the_file.so

(2) 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

(3) We add the desire 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

source : http://www.gnu.org/software/gsl/manual/html_node/Shared-Libraries.html

查看更多
疯言疯语
7楼-- · 2020-01-22 19:17
cd /home/<user_name>/
sudo vi .bash_profile

add these lines at the end

LD_LIBRARY_PATH=/usr/local/lib:<any other paths you want>
export LD_LIBRARY_PATH
查看更多
登录 后发表回答