dyld:未加载库...原因:找不到图像 [英] dyld: Library not loaded ... Reason: Image not found

查看:78
本文介绍了dyld:未加载库...原因:找不到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行我在 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"粘贴到那里时,它不再介意了.不幸的是,它抱怨找不到下一个 boost 库.

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?

推荐答案

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

Find all the boost libraries (where exefile is the name of your executable):

$ 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)

手册页:otoolinstall_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆