我使用gsl。在我编译了我的.cpp文件并运行它之后,我遇到了下面的错误:
加载共享库时出错:libgsl.so.0:无法打开共享对象文件:没有这样的文件或目录
我发现这个问题相同:https://groups.google.com/forum/#!topic/cortex_var/6vluX 7 pP 0 Sk & Linux错误加载共享库时:无法打开共享目标文件:没有这样的文件或目录& http://www.gnu.org/software/gsl/manual/html_node/Shared-Libraries.html
我已经按照上面的链接写了,但错误仍然存在。有人能帮助我吗?
9条答案
按热度按时间1hdlvixo1#
要使其工作,请执行以下步骤
启动Borne Shell
字符串
现在运行可执行文件
应该没问题
vfwfrxfs2#
首先,您需要定位文件(libgsl.so.0)。您可以使用
find
命令来完成此操作:字符串
让我们假设,该文件位于
/usr/local/lib
中。(如果没有找到该文件,请安装相应的软件包 * 或 * 下载源代码,构建并安装它。)现在,您有两个选择:(1)快速和肮脏:
型
这会将库的路径添加到环境变量中。此选项的缺点是,它仅对当前会话有效。它对其他用户无效。一旦您注销并再次登录,它将不起作用。
(2)永久性:
检查
/etc/ld.so.conf
。如果/usr/local/lib
没有列出,请添加它。现在,运行ldconfig
来检测共享目标文件并将其添加到系统范围的索引中。nwlls2ji3#
根据我的经验,fastStructure依赖于gsl 1.6,但不是最新版本。
字符串
将这些行添加到主目录下的
.bashrc
文件中。型
然后,运行source ~/.bashrc来设置这些环境变量。
当我将版本从最新版本更改为1.6时,它工作正常。
m3eecexj4#
我在Arch Linux上使用Krita时也遇到了同样的错误。
字符串
然后就修好了
70gysomp5#
字符串
例如:to-mr:加载共享库时出错:libgsl.so.19:无法打开共享对象文件:没有这样的文件或目录
jmp7cifd6#
你试过更新你的库吗?我试着运行的程序只需要一个更新的gsl版本(我有1.9.5,而它需要2.0.0或更新)。
如果你在arch上,你可以运行:
字符串
并选择合适的一个。
xdnvmnnf7#
你可以在makefile中使用
gsl-config --libs
,或者在命令行中链接gsl库。只要输入gsl-config
,你就可以找到它提供给你的选项。选择你需要的选项,你会发现编译和链接过程比以前容易得多。因此,当我在终端中输入gsl-config --libs
时,我得到-L/usr/local/lib -lgsl -lgslcblas -lm
。虽然它非常简单,首先你应该知道你的gsl安装在哪里。你可以将目录添加到PATH
环境变量中,或者使用绝对路径来执行gsl-config
。juud5qan8#
我需要
libgsl.so.19
:/snap/inkscape/current/bin/inkscape: error while loading shared libraries: libgsl.so.19: cannot open shared object file: No such file or directory
的我解决了它:
1.安装Anaconda
1.搜索
libgsl.so.19
并在~/anaconda 3/lib中找到它1.运行
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/anaconda3/lib
(最佳add it to ~/.basrc)0sgqnhkj9#
Max Ghenis和ManuelAtWork的解决方案帮助我解决了另一个共享库的相关问题。我想在这里记录我的步骤,以防它帮助其他人。
TL;DR
即使
LD_LIBRARY_PATH
包含/usr/local/lib
,并且您的共享对象库(.so
文件)也位于其中,您仍然可能会收到类似以下错误:error while loading shared libraries: <INSERT LIBRARY NAME>.so.0: cannot open shared object file: No such file or directory
个如果链接器缓存
/etc/ld.so.cache
在安装库后尚未重建。您可以通过运行
ldconfig
(或sudo ldconfig
,取决于/etc
目录权限,这些权限可能只能由root用户写入)来修复此问题。如果成功,
ldconfig
将不打印输出。要了解运行ldconfig
时的详细输出,请使用-v
(或--verbose
)标志。如果您曾经遇到过此错误,然后在您进行故障排除时它神奇地自行修复,那么可能是因为您遵循了某人的建议,并执行了以下操作
ldconfig -v | grep <INSERT LIBRARY NAME>
个以确保
.so
文件位于LD_LIBRARY_PATH中列出的目录中,如/usr/local/lib
。如果您已经确认该目录包含在/etc/ld.so.conf
或/etc/ld.so.conf.d/*.conf
中,但ldconfig -v
仍然在详细模式下 * 运行 *ldconfig
,这可能会重新构建/etc/ld.so.cache
,并修复您的问题,则执行此故障排除步骤是合理的。如果您的错误在一段时间后神秘地自行修复,而无需运行
ldconfig
,则系统上的其他东西必须从那时起运行它-例如启动脚本,计划任务或其他软件的安装脚本。详情
我最近安装了
libhttpserver
,按照其GitHub存储库上的说明,遵循make
命令的标准步骤。我能够针对库编译外部程序,但当我运行我的程序时,我收到了与动态链接相关的相同错误。字符串
error while loading shared libraries: libhttpserver.so.0: cannot open shared object file: No such file or directory
我确认
pkg-config
知道链接器标志和库名称,这意味着libhttpserver
的.pc
文件已经正确安装。型
我注意到了
-L/usr/local/lib
标志,并确认了共享目标文件位于那里。型
根据该线程的建议,我在
ldconfig -v
的输出中搜索了库名称型
我注意到输出末尾的错误消息
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
我决定阅读
ldconfig
的手册页来了解更多关于ldconfig -v
的功能。ldconfig creates the necessary links and cache to the most recent shared libraries found in the di‐rectories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories, /lib and /usr/lib
个型
由于
ldconfig -v
flag与ldconfig
做的是相同的事情,但只是有更详细的输出,我决定不使用它来运行ldconfig
。型
这一次,之前的错误信息是唯一的输出。在使用
sudo
之前,我想了解更多关于发生了什么。由于ldconfig
试图创建一个名为/etc/ld.so.cache~
的文件,我决定查找该文件或具有类似名称的文件。型
我想
/etc/ld.so.cache
一定是ldconfig
手册页所说的该高速缓存。我决定在那里查找我的库名称。$ grep libhttpserver /etc/ld.so.cache
但是
grep
没有返回匹配项,我转而查找/usr/local/lib
。型
在阅读
ldconfig
的手册页时,我了解到-p
标志以人类可读的格式打印该高速缓存,这是一个二进制文件,所以我在ldconfig -p
的输出中搜索/usr/local/lib
。ldconfig -p | grep /usr/local/lib
我在
/usr/local/lib
中找到了其他库的匹配项(例如libwayland,但没有libhttpserver
。型
很明显,链接器
ld.so
曾经能够找到位于/usr/local/lib
中的库,因为它们在链接器的缓存中。我通过检查/etc/ld.so.conf
和/etc/ld.so.conf.d
证实了这一点。$ cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
$ grep -x /usr/local/lib /etc/ld.so.conf.d/*.conf
/etc/ld.so.conf.d/libc.conf:/usr/local/lib
我很好奇在我的系统上运行
ldconfig
通常是什么,但是我找不到一个systemd服务,crontab,或者init.d脚本来运行它。在安装到/usr/local/lib
之前,我已经从源代码构建了库,但是我从来没有遇到过这个问题。我终于在我不久前安装的一个这样的库的源代码中的构建脚本中找到了对
ldconfig
的引用。我得出的结论是,安装后是否运行ldconfig
取决于源代码的作者,而系统是否在启动时自动运行ldconfig
等取决于您使用的是什么Linux发行版。在说服自己重新构建链接器缓存不会造成任何伤害之后,我最终以root身份运行
ldconfig
。sudo ldconfig
这一次,没有关于创建临时缓存文件失败的错误消息。在尝试再次运行代码之前,我确认链接器缓存现在包含对
libhttpserver
的引用。型
最后,我再次尝试运行程序,并取得了成功。
$ ./server
请注意,在运行
sudo ldconfig
之后,我不需要重新编译我的程序,因为它已经包含了对正确共享库的引用。问题只是在安装libhttpserver
之后,需要通过运行sudo ldconfig
来更新链接器缓存/etc/ld.so.cache
。当您从源代码构建库时,您可能会遇到这个问题,这取决于源代码维护者是否选择在其安装脚本中包含该步骤。