gpt4 book ai didi

c++ - ./a,输出 : error while loading shared libraries and linking

转载 作者:行者123 更新时间:2023-11-30 02:36:32 26 4
gpt4 key购买 nike

我正在尝试使用 portaudio 和 libaudiodecoder 编写一个简单的 c++ 程序来播放歌曲,只是我没有做到那么远......

测试.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"然后运行 ​​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 更新库缓存。

关于c++ - ./a,输出 : error while loading shared libraries and linking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32568490/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com