./a,out:加载共享库和链接时出错

./a,out: error while loading shared libraries and linking

本文关键字:链接 出错 共享 加载 out      更新时间:2023-10-16

我试图使用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命令更新库缓存