C++ 无法打开共享对象文件:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2172621/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:23:22  来源:igfitidea点击:

cannot open shared object file: No such file or directory

c++

提问by Tim

I met the share library not found on the head node of a cluster with torch. I have built the library as well as specify the correct path of the library while compiling my own program "absurdity" by g++. So it looks strange to me. Any idea? Thanks and regards!

我遇到了在带有torch的集群的头节点上找不到的共享库。我已经构建了库并指定了库的正确路径,同时通过 g++ 编译了我自己的程序“荒谬”。所以我觉得很奇怪。任何的想法?感谢致敬!

[tim@user1 release]$ make  
...  
...  
g++ -pipe -W -Wall -fopenmp -ggdb3 -O2    -I/home/tim/program_files/ICMCluster/ann_1.1.1/include -I/home/tim/program_files/ICMCluster/libsvm-2.89  -I/home/tim/program_files/ICMCluster/svm_light  -o absurdity  xxxxxx.o  -L/home/tim/program_files/ICMCluster/ann_1.1.1/release/lib -L/home/tim/program_files/ICMCluster/libsvm-2.89/release/lib -L/home/tim/program_files/ICMCluster/svm_light/release/lib -lm -ljpeg -lpng -lz -lANN -lpthread -lsvm -lsvmlight  

[tim@user1 release]$ ./absurdity  
./absurdity: error while loading shared libraries: libsvmlight.so: cannot open shared object file: No such file or directory  

[tim@user1 release]$ ls /home/tim/program_files/ICMCluster/svm_light/release/lib/libsvmlight.so -l  
-rwxr-xr-x 1 tim Brown 121407 Jan 31 12:14 /home/tim/program_files/ICMCluster/svm_light/release/lib/libsvmlight.so 

[tim@user1 release]$ LD_LIBRARY_PATH= /home/tim/program_files/ICMCluster/svm_light/release/lib:$LD_LIBRARY_PAT    
[tim@user1 release]$ export LD_LIBRARY_PATH 

[tim@user1 release]$ ./absurdity  
./absurdity: error while loading shared libraries: libsvmlight.so: cannot open shared object file: No such file or directory  

[tim@user1 release]$ ls  /home/tim/program_files/ICMCluster/svm_light/release/lib  
libsvmlight.a  libsvmlight.so  

回答by Tim ?as

Copied from my answer here: https://stackoverflow.com/a/9368199/485088

复制自我的回答:https: //stackoverflow.com/a/9368199/485088

Run ldconfigas root to update the cache - if that still doesn't help, you need to add the path to the file ld.so.conf(just type it in on its own line) or better yet, add the entry to a new file (easier to delete) in directory ld.so.conf.d.

ldconfig以 root 身份运行以更新缓存 - 如果这仍然没有帮助,您需要添加文件路径ld.so.conf(只需在其自己的行中输入)或者更好的是,将条目添加到新文件(更容易删除) ) 在目录中ld.so.conf.d

回答by Maurits Rijk

Your LD_LIBRARY_PATHdoesn't include the path to libsvmlight.so.

LD_LIBRARY_PATH不包括libsvmlight.so.

$ export LD_LIBRARY_PATH=/home/tim/program_files/ICMCluster/svm_light/release/lib:$LD_LIBRARY_PATH

回答by Shravan40

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)中找到的最新共享库。

Generally package manager takes care of this while installing the new library, but not always (specially when you install library with cmake).

通常包管理器在安装新库时会处理这个问题,但并非总是如此(特别是当您使用 安装库时cmake)。

And if the output of this is empty

如果这个输出是空的

$ echo $LD_LIBRARY_PATH

Please set the default path

请设置默认路径

$ LD_LIBRARY_PATH=/usr/local/lib

回答by duhaime

When working on a supercomputer, I received this error when I ran:

在超级计算机上工作时,我在运行时收到此错误:

module load python/3.4.0
screen
python

To resolve the error, I simply needed to reload the module in the screen terminal:

为了解决这个错误,我只需要在屏幕终端中重新加载模块:

module load python/3.4.0
python