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
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?
Find all the boost libraries:
$ 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)
and for each libboost_xxx.dylib
, do:
$ install_name_tool -change @executable_path/libboost_something.dylib /opt/local/lib/libboost_something.dylib exefile
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)
Manpages: otool
install_name_tool
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.
I have now made this script public on github.
This worked for me:
brew upgrade node
For some, this could be as easy as setting the system path for dynamic libraries. On OS X, this is as simple as setting the DYLD_LIBRARY_PATH
environment variable. See:
After upgrade Mac OS to Mojave. I tried to install npm modules via yarn
command I got error:
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
Was fix with:
brew update
brew upgrade
I got this error when I tried to install ruby 2.3.1 using rvm. It first told me to run brew update
, which I did, and then when I tried running rvm install ruby-2.3.1
, I received the error in this SO question.
The fix was to first run brew upgrade
, apparently according to this superuser.com question you need to do both brew update
&& brew upgrade
. Once that was done, I could finally install ruby 2.3.1.
You can use the otool command with the -L option for the executable, which will display where the executable is expecting those libraries to be.
If the path to those need changing, use the install_name_tool command, which allows you to set the path to the libraries.
I got here trying to run a program I just compiled using CMake. When I try to run it, it complains saying:
dyld: Library not loaded: libboost_system.dylib
Referenced from: /Users/path/to/my/executable
Reason: image not found
I circumvented the problem telling CMake to use the static version of Boost, instead of letting it use the dynamic one:
set(Boost_USE_STATIC_LIBS ON)
I fix it by brew install libpng
For anyone coming to this page because they got this error trying to link a third party framework to their project using Xcode 6.3.1, the problem I ran into was because the library was being created with an older version of the compiler using a different version of swift. The only way to fix this for me was to re-build the framework.
Another reason you might get this is stated in an Apple technical doc..
If you are building an app that does not use Swift but embeds content such as a framework that does, Xcode will not include these libraries in your app. As a result, your app will crash upon launching with an error message looking as follows:
set the Embedded Content Contains Swift Code (EMBEDDED_CONTENT_CONTAINS_SWIFT) build setting to YES in your app
Here is the link to the full Apple doc that explains it here
You can use sudo install_name_tool -change
change dylib path
And
sudo install_name_tool -id
change dylib name
For anyone experiencing the same thing with a different library or package, @user3835452 is on the right track. I found this message while trying to run composer
:
dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/opt/php@7.1/bin/php
Reason: image not found
Abort trap: 6
After trying a lot of different ways I just ran brew install openldap
and it fixed it. Note that I had already ran brew update
and brew upgrade
but only after I manually installed openldap
did it actually work.
I faced the app crash issue quoting SIGABRT error in thread.Overview of the crash is dyld library not loaded and image not found something like that.
This was seen in xcode 9.3 version.The reason i found out was xcode is not picking up libraries dynamically so i had to do it manually which solved my crash issue.
Follow the below steps: Step 1: Go to Build Phases Step 2: Hit the '+' button at the top and select "New Copy File Phase" Step 3 : Select Destination as Frameworks and Hit the '+' button below to add files. Step 4 : Select Add Other at below, click CMD+SHIFT+G and paste the below path, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
Now you will be able to see some swift dylibs, Select all the swift libraries with .dylib extension and click on open.
These will get added to the embedded binaries in the general tab of app.
Create a new group in project folder and add all these libraries.
Now run your app.
Happy Coding
Maybe someone need this:
if you use cmake, add DYLIB_INSTALL_NAME_BASE "@rpath"
to target properties:
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}"
)
or in xcode dynamic library project Target -> Build Setting set Dynamic Library Install Name Base to @rpath
I fixed this by reinstalling Homebrew
Uninstall
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
I fixed this issue by simply pressing Command + Shift + K, which makes a new clean build, really odd.
来源:https://stackoverflow.com/questions/17703510/dyld-library-not-loaded-reason-image-not-found