当我试图在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.5构建的iOS应用,使用cocoapods(如果你愿意,也可以是cocoapods-binary)。

我们看到了这样的崩溃:

dyld: Library not loaded: @rpath/PINOperation.framework/PINOperation
  Referenced from: /private/var/containers/Bundle/Application/4C5F5E4C-8B71-4351-A0AB-C20333544569/Tellus.app/Frameworks/PINRemoteImage.framework/PINRemoteImage
  Reason: image not found

原来我必须删除pod缓存并重新运行pod安装,所以Xcode会指出这个差异:

其他回答

以上这些对我都不起作用,但是brew重新安装icu4c起作用了。

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

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

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

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

我在这里试图运行一个我刚刚用CMake编译的程序。当我试图运行它时,它会抱怨说:

dyld: Library not loaded: libboost_system.dylib
  Referenced from: /Users/path/to/my/executable
  Reason: image not found

我绕过了这个问题,告诉CMake使用静态版本的Boost,而不是让它使用动态版本:

set(Boost_USE_STATIC_LIBS ON)

让构建阶段的框架成为可选框架对我来说很有用。

在Xcode ->目标->构建阶段->链接二进制与库-> 确保新添加的框架(如果有的话)被标记为可选