dyld:未加载库...原因:未找到图像 [英] dyld: Library not loaded ... Reason: Image not found
问题描述
在尝试运行我在Mac OS X中发送的可执行文件时,出现以下错误
When trying to run an executable I've been sent in Mac OS X, I get the following error
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"时,就不再关心它了.不幸的是,然后它抱怨找不到下一个增强库.
I have installed the boost libraries and they are located in /opt/local/lib
. I think the problem has something to do with the executable only looking in the directory it is in as when I paste the 'libboost_atomic.dylib' in there, it doesn't mind about it anymore. Unfortunately then it complains it can't find the next boost library.
有一种简单的方法可以解决此问题吗?
Is there an easy way to fix this?
推荐答案
查找所有增强库:
$ 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
进行验证:
and finally verify using otool
again:
$ 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)
联机帮助页: otool
Manpages: otool
install_name_tool
编辑前一段时间,我编写了python脚本(copy_dylibs.py
),以便在构建应用程序时自动计算所有这些内容.它将把/usr/local
或/opt/local
中的所有库打包到应用程序捆绑包中,并修复对这些库的引用以使用@rpath
.这意味着您可以使用Homebrew轻松安装第三方库并打包它们.
EDIT A while back I wrote a python script (copy_dylibs.py
) to work out all this stuff automatically when building an app. It will package up all libraries from /usr/local
or /opt/local
into the app bundle and fix references to those libraries to use @rpath
. This means you can easily install third-party library using Homebrew and package them just as easily.
我现在已经在 github 上将此脚本公开.
I have now made this script public on github.
这篇关于dyld:未加载库...原因:未找到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!