./a,out:加载共享库和链接时出错
./a,out: error while loading shared libraries and linking
我试图使用portaudio和libaudiodecoder编写一个简单的c++程序来播放一首歌,只是我没有得到那么远…
test.cpp
#include "libs/portaudio/include/portaudio.h" //portaudio
#include "libs/libaudiodecoder/include/audiodecoder.h" //libaudiodecoder
#include <iostream>
#include <string>
int main(int argc, char* argv)
{
std::string filename = argv;
AudioDecoderBase tester(filename);
std::cout << "test complete" << std::endl;
return 0;
}
然后运行:
gcc -L/usr/local/lib -lstdc++ test.cpp -lportaudio -laudiodecoder
编译(我得到一个关于argv类型的警告,说它应该是char**)。
当我运行a.o out test.mp3时,我得到:
./a.out: error while loading shared libraries: libaudiodecoder.so: cannot
open shared object file: No such file or directory
现在,我也有这个错误与portaudio,我相信我通过设置LD_LIBRARY_PATH="/usr/local/lib"然后运行sudo ldconfig来修复它。我检查了/usr/local/lib和libaudiodecoder。文件在这里。所以我很困惑,设置了环境变量(我仔细检查了一下),加载了配置,并且库文件位于正确的目录中。
注意:当我写这篇文章的时候,我运行了ls/usr/local/lib,只是为了确保库在那里,它在终端中显示为不同的颜色(绿色而不是青色),但是,我不确定这对文件说了什么。
有没有人知道我该如何解决这个问题?
您的问题是您的系统没有配置为从/usr/local/lib加载库GCC使用您提供的路径来查找库,但是系统动态加载器使用自己的路径。
你需要进入/etc/ld.so.conf或/etc/ld.so.conf。D并添加/usr/local/lib作为路径。然后运行ldconfig命令更新库缓存
相关文章:
- 读取文件的最后一行并输入到链接列表时出错
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 在发布模式下启动使用库的静态链接编译的应用程序时出错
- 编译时出错 - 链接.cpp和头文件
- 将 boost 与 Visual Studio 和 vcpkg 链接时出错
- 获取链接 创建flyweight_pattern时出错
- 从Qt5链接MySQL时出错
- 迭代器关系运算符出错(带单独链接和迭代器的自定义哈希表)
- 与 glfw3 链接时出错
- GNU 链接器:如果头文件中的指针被声明为 NULL 和/或 extern,则出错
- 可能的 GCC 链接器错误会导致将弱符号和局部符号链接在一起时出错
- 使用提升库和 clion 链接时出错
- 在 Fedora 27 中构建 GLFW 时链接期间出错
- 将 CLANG 构建的可执行文件与 G++-v6 构建的 Boost 库链接时出错
- 链接 gtest 项目时出错
- 链接webrtc本机时出错,因为未定义对具有std::string的方法的引用
- wxwidget 3.1.2 代码块 17.04 在链接步骤中出错
- 链接Firebase C (分析)库时出错
- 在Windows上使用GCC的链接时间优化构建wxWidgets DLL时出错
- 链接外部变量 c++ 时出错