无法使用犰狳运行编译的 cpp 代码,因为 dyld:库未加载

Can't run compiled cpp code with armadillo, because of dyld: Library not loaded

本文关键字:因为 代码 dyld 加载 cpp 编译 运行      更新时间:2023-10-16

我按照这里的安装说明(Mac OS(进行操作:

https://gitlab.com/conradsnicta/armadillo-code/#5-linux-and-macos-installation

我成功编译了示例代码,如下所示:

http://arma.sourceforge.net/docs.html#example_prog

g++ example1.cpp -o example1 -O2 -larmadillo

然后我尝试运行输出,但出现以下错误:

dyld: Library not loaded: @rpath/libhdf5.101.dylib
Referenced from: /usr/local/lib/libarmadillo.9.dylib
Reason: image not found
Abort trap: 6

有什么想法如何让它工作吗?

在构建应用程序时,您需要-rpath链接器选项来告诉加载程序在何处查找该库。

通常,Mac应用程序是它自己的文件夹树,称为捆绑包。在那里,您将放置库文件,然后在应用程序二进制文件中列出@executable_path/relative_path_to_library,作为加载程序看到@rpath时查看的位置。

延伸阅读: 运行路径相关库

我在犰狳上遇到了完全相同的错误。我所做的是首先卸载犰狳(这可能不是必需的(。然后我做了brew install armadillo --with-hdf5.由于这是一个链接问题(犰狳在错误的地方寻找libhdf5.101.dylib(,我接下来做了brew link armadillo.然后,如果您收到冲突的文件错误,只需执行brew link --overwrite armadillo.祝你好运!

相关文章: