dyld: Library not loaded ... Reason: Image not found
Asked Answered
M

42

409

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?

Mourner answered 17/7, 2013 at 15:8 Comment(2)
If you still has problem use method from this topicPreparedness
Try to uninstall python3.7.3 using this:- huybien.com/how-to-completely-uninstall-python-on-macosFoldboat
W
222

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)

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.

Wittenburg answered 17/7, 2013 at 15:40 Comment(11)
@Wittenburg can you please explain here what is the exefile is it be a tool exec file path ? isnt it ?Jurisconsult
After recompiling the executable I have to repeat this process - quite annoying during development.Tacet
Actually the better way is to use DYLD_LIBRARY_PATH to modify the search path. The other answer has got this.Annalist
'exefile': No such file or directoryChaoan
@Chaoan exefile stands for the executable file you're trying to run. In my case, otool -L /usr/local/bin/php did the trick.Ahola
Thanks! Worked for me when Homebrew messed up bash. In my case I needed to run install_name_tool as root to get over the issue. This one-liner inspects all the dylibs for a binary: otool -L /usr/local/bin/bash | awk -F' ' '{print $1}' | tail -n +2 | xargs -I{} ls {}Sandor
Here's the other way. Please take a look. github.com/eXolnet/homebrew-deprecated/issues/27Sheldonshelduck
@YuAnShaolinMaculelêLai Sorry I don't understand what you mean.Wittenburg
@Annalist - Which answer exactly is the "other answer"?Cornered
@SecurityHound This is the one.Annalist
Using DYLD_LIBRARY_PATH doesn't seem to work for me. Thankfully install_name_tool does.Hendershot
N
170

This worked for me:

brew upgrade node
Nowell answered 9/5, 2018 at 20:14 Comment(7)
What is this doing, though?Naumachia
@Naumachia this is reinstalling node using homebrew. Probably another installation broke node path. Also worked for me.Unthread
It worked for me after updating macOS Catalina. Thanks!Acceptance
Same here, I fixed it with brew upgrade node (OSX Catalina)Tropopause
This should be the accepted answer. Save most people a lot of hassle.Vicissitude
@JeremyMoritz Except that the question doesn't even mention node and is not tagged with node. It's an answer to a different question.Wittenburg
This worked for my Mac OSX CatalinaFinbar
I
127

In the target's General tab, there is a section called Frameworks, Libraries, and Embedded Content

Click on the + sign, add required framework and the crash is resolved.

Update latest xcode screen-shot

Icecap answered 10/5, 2016 at 7:22 Comment(4)
what should i add ? there's a lot of filesBrownout
@Himanshu I have libcppreset for my project! it has a lot of dependency from boost and ... I run a bash script to change them with install_name_tool but for the LC_ID_DYLIB I can't so need to make a symlink in usr/loca/opt ! is there any way to figure out ? :| It's painfull :(Lilybel
Add the framework and set the framework to Embed & SignLui
I just removed and added again the library and it workedSaretta
J
117

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 fixed with:

brew update
brew upgrade
Jenijenica answered 7/1, 2019 at 10:39 Comment(3)
My intelliJ started throwing this error when I recently updated xcode. I was trying to run a node.js server through intellij. I wasn't sure what went wrong. Running node --version on my system resulted in the same error. Running the above two commands solved my problem.Aeneous
In my case, I also ran the brew cleanup command, which is good to do at times if you want to get rid of old versions.Bernt
Regarding to @MichaelBehrens's comment, I run brew cleanup then it fixed.Miniskirt
N
45

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:

Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?

Nolde answered 27/1, 2016 at 1:4 Comment(5)
It may seem stupid, but I wonder what value should I set DYLD_LIBRARY_PATH to?Formerly
@Caesar Set it to the directory of wherever the dylibs you're trying to link are located.Nolde
You cannot expect your users to change DYLD_LIBRARY_PATH. The correct solution is to include non-standard libraries with the .app and the user won't have to do anything. The developer, however, may still have to hack the loader path as per my answer.Wittenburg
@Wittenburg .app? Have a test executable, trying to link some .dylib . Linux is same with LD_LIBRARY_PATHGewgaw
So easy. Thank you! Wonder, what other answers are about, and how brew would do a similair thing ...Gewgaw
R
42

this should fix the issue

brew update
brew upgrade
brew cleanup
Reredos answered 20/6, 2020 at 8:39 Comment(6)
Using this worked for me, unfortunately, I still don't know what cause of the issue to begin with or why updating, upgrading and cleaning up solve the issueMoan
this worked totally for me, however, while trying to do the cleanup, i ran into some permission issue, if you also have this trouble, try running sudo chown -R $(whoami) /usr/local/lib then try running the brew cleanup againXanthin
I still get ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_' (/Users/foo/.local/share/virtualenvs/TMIWqqTS/lib/python3.7/site-packages/urllib3/util/ssl_.py) after running thisGnarled
I fixed my follow up error by reinstalling python. I use asdf to manage my language versions so I did asdf uninstall python 3.7.3 (I was using 3.7.3, specify here the version you have) and then ran asdf install python 3.7.3.Gnarled
if till not work : brew services start phpCulver
I had to follow this as well: https://mcmap.net/q/82570/-error-cannot-install-in-homebrew-on-arm-processor-in-intel-default-prefix-usr-localOmni
O
12

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.

Obliquity answered 21/10, 2016 at 11:41 Comment(1)
People need to stop recommending doing brew upgrade just like that. This can be a massive disruptor for one's entire system. Instead, isolate what needs to be upgraded and upgrade that only.Lovegrass
S
12

Now that Xcode has upgraded their IDE, they have changed a little bit how this functions.

It used to be split up into separate section as demonstrated above with 'Embedded Binaries' and 'Linked Frameworks and Libraries' as separate sections.

Now, it is one combined section with drop-downs on the right as to what should be embedded.

New IDE Changes

This was confusing to me at first, but makes perfect sense now.

Susannsusanna answered 30/9, 2019 at 14:4 Comment(0)
W
11

If you're using Xcode 11 onwards:

Go to General tab and add the framework in Frameworks, Libraries, and Embedded Content section.

Important: By default it might be marked as Do Not Embed, change it to Embed Without Signing like shown in the image and you are good to go.

enter image description here

For Xcode versions below 11:

Just add the framework in Embedded Binaries section and you are done.

Cheers!

Waterresistant answered 30/11, 2019 at 18:48 Comment(2)
I had the same problem. In my case choosing "Embed & Sign" worked.Incontinent
Yes it depends on the library if it was signed by the developer or not. Most of the times frameworks are not signed. But there may be cases when these are signed. I also had to select 'Embed & Sign' for a Google framework.Waterresistant
A
10

To resolve the error below on my Macbook Catalina 10.15.4:

dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
    Referenced from: /usr/local/bin/mongoexport
    Reason: image not found
Abort trap: 6

I ran the command below and got round the problem above:

brew switch openssl 1.0.2s
Accelerant answered 25/5, 2020 at 21:35 Comment(2)
any explanations on this would be helpful.Mesencephalon
Looks to me like the executable shouldn't even be linking against libssl.1.0.0.dylib, but rather libssl.1.dylib, which will be symlinked to the exact version on the system while maintaining API compatibility. See this.Wittenburg
T
8

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.

Tympanitis answered 17/7, 2013 at 15:26 Comment(0)
S
7

Making the Frameworks in the Build Phases Optional worked for me.

In Xcode -> Target -> Build Phases -> Link Binary with Libraries -> Make sure the newly added frameworks if any are marked as Optional

Swampy answered 28/8, 2020 at 1:50 Comment(0)
O
5

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)
Oodles answered 30/6, 2015 at 2:35 Comment(0)
C
3

I fix it by brew install libpng

Coseismal answered 16/3, 2018 at 5:49 Comment(0)
D
3

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

Davit answered 27/2, 2019 at 6:48 Comment(1)
I create a cocoa framework dynamic library project, it works, and compared with my bad cmake generated project find this different, and fixed it, it works on iOS.Davit
A
3

I fixed this issue by using Product > Clean Build Folder (CommandShiftK), which makes a new clean build, really odd.

Abebi answered 21/3, 2019 at 5:27 Comment(0)
S
3

For my framework I was using an Xcode subproject added as a git submodule.

I believe I was getting this error because I was signing the framework with a different signing Team than my main app. (switched teams for app; forgot to switch for framework)

Solution is to not sign within the framework project. Instead, in the main app's Target > General > Frameworks, Libraries, and Embedded Content section, sign the framework via Embed & Sign.

If I select Do not Embed or Embed Without Signing I instead get the error:

FRAMEWORK not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

Sorosis answered 18/12, 2019 at 9:48 Comment(0)
G
2

You can use sudo install_name_tool -change change dylib path And sudo install_name_tool -id change dylib name

Gothart answered 12/12, 2016 at 6:39 Comment(0)
A
2

Xcode 11.1 & Swift 5.1

Quick Fix

First make sure that external added library has option embed is selected in General Tab, Embbed Binaries.

If still not works..

This happens because you have different, unmatched versions of libraries present.

Update the Pods

pod update

Important: Check all libraries are included in the Build Settings -> libraries and frameworks list and you have given option to embbed in the build

Just working awesome

Andrel answered 10/10, 2019 at 9:6 Comment(0)
T
2

if you use virtualenv just remove the folder of your environment and recreate it with this command virtualenv --python=/usr/local/bin/python3 the_name_of_my_env

Taneka answered 26/11, 2019 at 16:50 Comment(0)
O
2

In our case, it's an iOS app, built on Xcode 11.5, using cocoapods (and cocoapods-binary if you will).

We were seeing this crash:

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

Turns out that I had to delete the pods cache and re-run pod install, so Xcode would point this diff:

enter image description here

Optical answered 6/7, 2020 at 21:4 Comment(0)
A
1

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

Allembracing answered 28/4, 2015 at 1:22 Comment(0)
A
1

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/[email protected]/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.

Ahola answered 25/11, 2018 at 6:42 Comment(1)
I had a similar problem dyld: Library not loaded:/usr/local/opt/fftw/lib/libfftw3f.3.dylib. After checking many possible solutions I just did brew install fftw and it worked for me. Thanks @AholaIsador
H
1

Is there an easy way to fix this?

I just used brew upgrade <the tool>. In my case, brew upgrade tmux.

Horologium answered 19/9, 2019 at 10:18 Comment(0)
G
1

In my case it was node that was out of date, you need to upgrade it after goin up to BigSur - brew upgrade node

Gastrocnemius answered 23/12, 2020 at 11:4 Comment(0)
N
1

As said in https://gist.github.com/berkedel/d1fc6d13651c16002f64653096d1fded, you could try

brew uninstall --ignore-dependencies node icu4c
brew install node
brew link --overwrite node
Nutgall answered 14/4, 2021 at 11:29 Comment(0)
L
1

Quick Fix

  • Remove the pod (whose name is in the error) by commenting it in your Podfile, like #Podname
  • Run pod install
  • Uncomment the pod that you commented earlier
  • Run pod install again.

It worked for me and is easy to do so sharing it.

Lodgings answered 3/11, 2021 at 15:46 Comment(0)
S
0

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. 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:

  1. Go to Build Phases
  2. Hit the '+' button at the top and select "New Copy File Phase"
  3. Select Destination as Frameworks and Hit the '+' button below to add files.
  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.

Solipsism answered 18/5, 2018 at 7:24 Comment(0)
M
0

If you are using Conda environment in the terminal, update the samtools to solve it.

conda install -c bioconda samtools

Matriarchate answered 22/4, 2020 at 11:5 Comment(0)
B
0

Best one is answered above first check what is the output of

otool -L

And then do the following if incorrect

set_target_properties(
    MyTarget
    PROPERTIES
    XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS
    "@executable_path/Frameworks @loader_path/Frameworks"
)

And

set_target_properties(
        MyTarget
        PROPERTIES
        XCODE_ATTRIBUTE_DYLIB_INSTALL_NAME_BASE 
        "@rpath"
Benzine answered 17/5, 2020 at 9:29 Comment(0)
G
0

I got this error after using asdf to switch my python version. When you activate the virtualenv it gets confused.

Instead recreate the virtualenv like so

$ rm -rf venv
$ python -m venv venv

This time when you activate the virtualenv it will find the correct python.

Gnarled answered 23/7, 2020 at 16:55 Comment(0)
B
0

It is an dynamic linker error which links binary in load or runtime

[@rpath]

Blaine answered 6/4, 2021 at 14:43 Comment(0)
T
0

enter image description here

  1. Select your project
  2. Go To Targets
  3. Go To Frameworks, Libraries, and Embedded Content
  4. Click at the + icon
  5. You should get a prompt => Search for your missed library; -in my case was OpenSSL-.
  6. Select it and add it.
  7. clean your project.
  8. Re-build.
Termite answered 10/4, 2021 at 10:28 Comment(0)
P
0

FIXED: This approach cleared this up for me with ease ...

My particular CLI tool that triggered the same issue (i.e., netdiscover), was looking for:

/usr/local/opt/libnet/lib/libnet.1.dylib

When I searched that path for, libnet.1.dylib, ls returned a file, but a newer version: libnet.9.dylib

Following the approach presented in this article, How to Fix ‘Dyld: Library not Loaded’ Error on MacOS, I was able to fix the issue by simply creating a symlink pointer to the file that the tool was looking for (i.e., libnet.1.dylib), to that of the new file version listed on my system (i.e., libnet.9.dylib), ...

ln -s /usr/local/opt/libnet/lib/libnet.9.dylib /usr/local/opt/libnet/lib/libnet.1.dylib

... now when I run the tool, it finds the dependancies it needs without complaint!, : )

--AA

Reference:

Passkey answered 26/10, 2021 at 19:33 Comment(0)
R
0

This was my reason of the issue:

dyld: Library not loaded: /System/Library/Frameworks/AVFAudio.framework/AVFAudio   Referenced from: /private/var/containers/Bundle/Application/B6724E76-E704-46A2-8637-F43277018CE2/MyFrameworkUsageSample.app/Frameworks/MyFramework.framework/MyFramework Reason: image not found dyld: launch, loading dependent libraries DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

I was creating own framework MyFramework - where the Apple Framework was used. And build the xcframework with latest deployment target - iOS 16. While in the TestApp required to run on iOS 13+. And The Test Devices were using iOS 15.

Thus the TestApp with MyFramework was launching on Simulator (iOS16) successfully. But not on the Devices.

Resolution: In MyFramework - change the deployment target to needed iOS. And re-generate your framework. Or if you are using the 3d-party framework - ask the provider to support you minimal deployment target.

So missed to change the min deployment target in the xcframework before building - and Apple logs were as usual super helpful)))

Rizzio answered 26/11, 2022 at 6:19 Comment(0)
B
0
install_name_tool -add_rpath new_path executable
install_name_tool -delete_rpath old_path  executable
Birthwort answered 25/1, 2023 at 6:58 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Characteristic
P
0

Removing older php version is fixed my problem, like:

 brew remove [email protected]
Privateer answered 30/11, 2023 at 15:31 Comment(0)
C
0

In my case there was Target A, Target B and pod. Target A embedding target B. Target B has in podfile lib Alamofire.

If Target A not having Alamofire in Podfile, there was an error.

To fix it, I had to add pod Alamofire into Target A and Target B the both. Despite Target A not using Alamofire.

Caroleecarolin answered 17/1, 2024 at 14:40 Comment(0)
G
-1

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

Grownup answered 14/3, 2019 at 15:2 Comment(0)
H
-1

For anyone that might still be having this problem:

This is an ongoing problem on Apple's side, and what worked for me is upgrading to ios 13.4(beta). Installed that and worked like a charm.

Hindoo answered 28/2, 2020 at 18:40 Comment(1)
this is not IOS issue.Gosse
I
-1

I forgot to add use_frameworks! in my podfile. I added it back and it worked.

Importune answered 28/4, 2021 at 8:44 Comment(0)
B
-2

None of the above worked for me, but brew reinstall icu4c did.

Bobbitt answered 25/9, 2019 at 7:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.