解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
程序员文章站
2022-07-15 16:45:17
...
一、问题
运行hello程序时,用到了自己编写的动态库,在目录/usr/local/lib目录下,运行时出现
error while loading shared libraries: libhello.so.1: cannot open shared object file: No such file or directory
分析原因:链接器ld提示找不到库文件。ld默认的目录是/lib和/usr/lib,如果放在其他路径也可以,需要让ld知道库文件所在的路径。找不到这个动态库,CMakeLists.txt是这样写的:
cmake_minimum_required(VERSION 3.0)
INCLUDE_DIRECTORIES(/usr/local/include/hello)
LINK_directories("/usr/locla/lib")
ADD_EXECUTABLE(main main.c)
TARGET_LINK_LIBRARIES(main libhello.so)
这里已经指定了,可是还出现上面问题,根据错误提示找到博客:https://blog.csdn.net/yjk13703623757/article/details/53217377
解决方法如下:
方法1:
# vim /etc/ld.so.conf //在新的一行中加入库文件所在目录
/usr/lib
# ldconfig //更新/etc/ld.so.cache文件
方法2:
1.将用户用到的库统一放到一个目录,如 /usr/loca/lib
# cp libXXX.so.X /usr/loca/lib/
2.向库配置文件中,写入库文件所在目录
# vim /etc/ld.so.conf.d/usr-libs.conf
/usr/local/lib
3.更新/etc/ld.so.cache文件
# ldconfig
附加:
如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,
搜索出可共享的动态链接库(格式如lib*.so*), 进而创建出动态装入程序(ld.so)所需的连接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态链接库名字列表.
上一篇: 使用vs2019发布项目“从与我的应用程序相同位置下载系统组件”报错
下一篇: git拉取分支
推荐阅读
-
解决启动MongoDB错误:error while loading shared libraries: libstdc++.so.6:cannot open shared object file:
-
解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
-
error while loading shared libraries: xxx: cannot open shared object file: No such file or directory
-
gmx-MMPBSA — error while loading shared libraries: libgfortran.so.3: cannot open shared object file
-
mysql初始化/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
-
cv2报错ImportError: libXrender.so.1: cannot open shared object file 解决
-
解决 ImportError: libcublas.so.9.0: cannot open shared object file: No such file
-
错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory,errorwhileloading_PHP教程
-
错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory,errorwhileloading_PHP教程
-
php: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No