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

测试文件

#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以更新库高速缓存。

09-09 23:26
查看更多