./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.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" 然后 运行ning sudo ldconfig 修复了它。我检查了 /usr/local/lib 并且 libaudiodecoder.so 文件在那里。所以我很困惑,设置了环境变量(我仔细检查过),加载了配置,库文件在正确的目录中。

注意:我 运行 ls /usr/local/lib 因为我写这篇文章只是为了确保库在那里,它在终端中显示为不同的颜色(绿色而不是青色),但是,我不确定这对文件有何影响。

有人知道我该如何解决这个问题吗?

您的问题是您的系统未配置为从 /usr/local/lib 加载库。 GCC 使用您提供的路径来查找库,但系统动态加载程序使用它自己的路径。

您需要转到 /etc/ld.so.conf 或 /etc/ld.so.conf.d 并添加 /usr/local/lib 作为路径。然后运行 ldconfig更新库缓存。