当我试图在Mac OS X中运行一个可执行文件时,我得到以下错误

dyld: Library not loaded: libboost_atomic.dylib
  Referenced from: /Users/"Directory my executable is in"
  Reason: image not found
Trace/BPT trap:5

我已经安装了boost库,它们位于/opt/local/lib中。我认为这个问题与可执行文件只在它所在的目录中查找有关,因为当我粘贴'libboost_atomic。Dylib '在那里,它不再介意了。不幸的是,它会抱怨找不到下一个增强库。

有没有简单的方法来解决这个问题?


当前回答

Xcode 11.1 & Swift 5.1

快速修复

首先确保外部添加的库有选项embed被选择在General Tab, embdbbinaries。

如果还是不行…

出现这种情况是因为存在不同的、不匹配的库版本。

更新Pods

pod update

重要提示:检查所有库都包含在构建设置->库和框架列表中,并且您已经在构建中嵌入了选项

工作非常棒

其他回答

您可以对可执行文件使用otool命令和-L选项,这将显示可执行文件期望这些库的位置。

如果需要更改这些库的路径,请使用install_name_tool命令,该命令允许您设置库的路径。

如果您在终端中使用Conda环境,请更新samtools以解决该问题。

第二个install -c bioconda samtools

找到所有的boost库(其中exefile是你的可执行文件的名称):

$ otool -L exefile
exefile:
        @executable_path/libboost_something.dylib (compatibility version 0.7.0, current version 0.7.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 65.1.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

对于每个libboost_xxx。dylib,做:

$ install_name_tool -change @executable_path/libboost_something.dylib /opt/local/lib/libboost_something.dylib exefile

最后再次使用otool进行验证:

$ otool -L exefile
exefile:
        /opt/local/lib/libboost_something.dylib (compatibility version 0.7.0, current version 0.7.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 65.1.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

Manpages: otool install_name_tool

编辑前一段时间,我写了一个python脚本(copy_dylib .py),在构建应用程序时自动解决所有这些问题。它会将/usr/local或/opt/local中的所有库打包到应用程序包中,并使用@rpath修复对这些库的引用。这意味着您可以轻松地使用Homebrew安装第三方库并轻松地打包它们。

我现在已经在github上公开了这个脚本。

Install_name_tool -add_rpath new_path可执行文件 Install_name_tool -delete_rpath old_path可执行文件

如https://gist.github.com/berkedel/d1fc6d13651c16002f64653096d1fded中所说,你可以试试

brew uninstall --ignore-dependencies node icu4c
brew install node
brew link --overwrite node