当我试图在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 '在那里,它不再介意了。不幸的是,它会抱怨找不到下一个增强库。

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


当前回答

Mac OS升级到Mojave后。我试图通过yarn命令安装npm模块,我得到错误:

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib
  Referenced from: /usr/local/bin/node
  Reason: image not found
Abort trap: 6

被固定为:

brew update
brew upgrade

其他回答

如果使用cmake,在目标属性中添加DYLIB_INSTALL_NAME_BASE "@rpath":

set_target_properties(target_dyLib PROPERTIES
        # # for FRAMEWORK begin
        # FRAMEWORK TRUE
        # FRAMEWORK_VERSION C
        # MACOSX_FRAMEWORK_IDENTIFIER com.cmake.targetname
        # MACOSX_FRAMEWORK_INFO_PLIST ./Info.plist
        # PUBLIC_HEADER targetname.h
        # # for FRAMEWORK end
        IPHONEOS_DEPLOYMENT_TARGET "8.0"
        DYLIB_INSTALL_NAME_BASE "@rpath" # this is the key point
        XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
        DEVELOPMENT_TEAM "${DEVELOPMENT_TEAM}"
    )

或者在Xcode动态库项目Target -> Build Setting中将动态库安装名库设置为@rpath

找到所有的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上公开了这个脚本。

如果使用virtualenv,只需删除环境的文件夹并使用此命令重新创建它 Virtualenv——python=/usr/local/bin/python3 the_name_of_my_env . txt

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

第二个install -c bioconda samtools

快速修复

删除pod(其名称在错误中)通过在Podfile中注释它,如#Podname 运行pod安装 取消注释之前注释过的pod 再次运行pod install。

这对我来说很有效,所以分享它很容易。