dyld: Library not loaded ... Reason: Image not found

422,185

Solution 1

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.

Solution 2

This worked for me:

brew upgrade node

Solution 3

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

Solution 4

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

Solution 5

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?

Share:
422,185
rwolst
Author by

rwolst

Updated on November 04, 2021

Comments

  • rwolst
    rwolst over 2 years

    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?

  • VenushkaT
    VenushkaT over 9 years
    @trojanfoe can you please explain here what is the exefile is it be a tool exec file path ? isnt it ?
  • Leo
    Leo about 7 years
    It may seem stupid, but I wonder what value should I set DYLD_LIBRARY_PATH to?
  • markshiz
    markshiz about 7 years
    @Caesar Set it to the directory of wherever the dylibs you're trying to link are located.
  • tglas
    tglas over 6 years
    After recompiling the executable I have to repeat this process - quite annoying during development.
  • frankliuao
    frankliuao almost 6 years
    Actually the better way is to use DYLD_LIBRARY_PATH to modify the search path. The other answer has got this.
  • ScottyBlades
    ScottyBlades almost 6 years
    'exefile': No such file or directory
  • brunouno
    brunouno over 5 years
    @ScottyBlades exefile stands for the executable file you're trying to run. In my case, otool -L /usr/local/bin/php did the trick.
  • Joe Sleiman
    Joe Sleiman over 5 years
    what should i add ? there's a lot of files
  • trojanfoe
    trojanfoe over 5 years
    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.
  • cn00
    cn00 about 5 years
    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.
  • diegoaguilar
    diegoaguilar almost 5 years
    What is this doing, though?
  • Hugo Nogueira
    Hugo Nogueira over 4 years
    @diegoaguilar this is reinstalling node using homebrew. Probably another installation broke node path. Also worked for me.
  • Ishan
    Ishan over 4 years
    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.
  • Matt Kneiser
    Matt Kneiser over 4 years
    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 {}
  • Michael Behrens
    Michael Behrens over 4 years
    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.
  • JBarros35
    JBarros35 about 4 years
    this is not IOS issue.
  • Mo Farhand
    Mo Farhand about 4 years
    @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 :(
  • Jivan
    Jivan about 4 years
    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.
  • Buraco
    Buraco about 4 years
    Regarding to @MichaelBehrens's comment, I run brew cleanup then it fixed.
  • Onema
    Onema almost 4 years
    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 issue
  • Pianistprogrammer
    Pianistprogrammer almost 4 years
    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 again
  • Harry Moreno
    Harry Moreno almost 4 years
    I still get ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_' (/Users/foo/.local/share/virtualenvs/TMIWqqTS/lib/python3.7/‌​site-packages/urllib‌​3/util/ssl_.py) after running this
  • Harry Moreno
    Harry Moreno almost 4 years
    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.
  • Cadu De Castro Alves
    Cadu De Castro Alves almost 4 years
    It worked for me after updating macOS Catalina. Thanks!
  • Ejaz Karim
    Ejaz Karim over 3 years
    any explanations on this would be helpful.
  • YuAn Shaolin Maculelê Lai
    YuAn Shaolin Maculelê Lai over 3 years
    Here's the other way. Please take a look. github.com/eXolnet/homebrew-deprecated/issues/27
  • trojanfoe
    trojanfoe over 3 years
    @YuAnShaolinMaculelêLai Sorry I don't understand what you mean.
  • trojanfoe
    trojanfoe over 3 years
    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.
  • inaki
    inaki about 3 years
    Same here, I fixed it with brew upgrade node (OSX Catalina)
  • shorol
    shorol about 3 years
    if till not work : brew services start php
  • desu sai venkat
    desu sai venkat over 2 years
    Add the framework and set the framework to Embed & Sign
  • Jeremy Moritz
    Jeremy Moritz over 2 years
    This should be the accepted answer. Save most people a lot of hassle.
  • trojanfoe
    trojanfoe over 2 years
    @JeremyMoritz Except that the question doesn't even mention node and is not tagged with node. It's an answer to a different question.
  • Joana Carvalho
    Joana Carvalho about 2 years
    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 @brunouno
  • Sam Ginrich
    Sam Ginrich about 2 years
    @trojanfoe .app? Have a test executable, trying to link some .dylib . Linux is same with LD_LIBRARY_PATH
  • Sam Ginrich
    Sam Ginrich about 2 years
    So easy. Thank you! Wonder, what other answers are about, and how brew would do a similair thing ...