How to Fix ‘Dyld: Library not Loaded’ Error on MacOS

MacOS developed and distributed by Apple is surely one of the most reliable Operating System out there. It is used mostly by professionals who intend to use their computers for business purposes. However, quite recently a lot of reports have been coming in of a “Dyld: Library Not Loaded” Error on MacOS. In this article, we will discuss the reason due to which this error is triggered and also provide viable solutions in order to fix them.

“dyld: Library not Loaded” Error Message on MacOS

What Causes the “Dyld: Library Not Loaded” Error on MacOS?

After receiving numerous reports, we decided to investigate the issue and identified the reason due to which this error is triggered.

  • Invalid Location: This error is triggered when the computer tries to find the “libmysqlclient.18.dylib” file or a file similar to that under the “usr/lib” location. The file is quite obviously not present in this location due to which the error is triggered.

Now that you have a basic understanding of the nature of the problem we will move on towards the solutions. Make sure to implement these in the specific order in which they are provided to avoid any conflicts.

Solution 1: Creating a Symbolic Link

It is possible to counter the problem by creating a Symbolic Link in the directory where the computer is checking for the “.dylib” file. In order to do that:

  1. Navigate to the “/usr/lib” folder.
  2. Press the “Command” + “Space” simultaneously.
  3. Type in “Terminal” and press “Enter“.
    MacOS Terminal
  4. Type the following command in the terminal and press “Enter
    sudo ln -s /path/to/your/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

    An example of the above command looks like this:

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  5. Check to see if the issue persists.

Solution 2: Updating Brew

In some cases, this file is missing from the directory due to an outdated installation of “Brew”. Therefore, in this step, we will be updating Brew. In order to do that:

  1. Press the “Command” + “Space” simultaneously.
  2. Type in “Terminal” and pressEnter“.
    MacOS Terminal
  3. Type in the following command in the terminal and press “Enter“.
    brew update
  4. Again, type in the following command in the terminal and press “Enter”.
    brew upgrade
  5. Check to see if the issue persists.

Solution 3: Running a “Copy_dylibs.py” Script

In some cases, the references for the “.dylib” files aren’t correct due to which this error is triggered. Therefore, in this step, we will be running a script which will automatically detect and fix these issues. In order to do that:

  1. Click on this link and download the script.
  2. Extract the contents of the “.zip” file.
    Contents of the zip file
  3. Read the “readme” included in the “.zip” file carefully for detailed instructions.
  4. Run the “copy_dylibs.py” script and let it fix the issue
  5. Check to see if the issue persists.
ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.

Comments

11
    MK
    Mike Ill Kilmer Jun 10, 2020

    Thanks for sharing this, Kevin. This error has been a nuisance that keeps popping up for a while now, specifically with my install of php Composer and somehow related to the `henkrehorst/php/valet-php@7.0` dependency of a library called Valet+, which is a fork of Laravel’s Valet tool. I’m starting by updating and upgrading Brew… which is taking a long time today (I guess since everyone in the world is home on their computer)… That seemed to work. The python script looks pretty interesting. Thanks a lot for taking the time to share this, man. Peace.

    SG
    Shrutee Gangras Jul 22, 2020

    Thanks for sharing this. Updating and upgrading brew worked for me. Thanks.

    AB
    Abhilash Nov 14, 2020

    Hi Kevin, I tried out the solutions you described; unfortunately they don’t work for me. This is after the new big sur update. Thoughts?

    dyld: Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
    Reason: image not found
    Abort trap: 6

      MZ
      Muhammad Zubyan Author Nov 17, 2020

      It can be an issue with your ruby and vim links so First of all, try this command to overwrite brew ruby linkbrew link –overwrite rubyif that doesn’t work for you try to reinstall ruby and vim. Here is the command:-brew reinstall ruby vimHope this helps! Keep me updated.

      Reply
    KD
    KD19 Dec 5, 2020

    What do i do if the terminal asks for a password?

      MZ
      Muhammad Zubyan Author Dec 6, 2020

      You can type your account password in that field. Also, when you are typing it will not show the password on your screen simply type the whole password and the terminal should be available for you.

    DS
    David R. Sterry May 20, 2021

    Just ran into this after a Big Sur and brew upgrade and a bunch of other setup. The error showed when attempting to invoke the python interpreter from within a virtual environment. None of the above worked but what did was to `brew reinstall python` and then create a new env with `virtualenv -p python3 env`. Thanks for posting this as it helped generate the solution.

    Reply
    JR
    Jean-Louis Regez Oct 29, 2021

    Hi,
    I have been quite happy to find your hints about this problem.
    I use the GD library from plain C and got the same error message
    on MACOS ElCapitan and the JPEG library installed via macports.
    sudo port install jpeg did update all needed references andeverything works fine now.
    Regards
    Jean-Louis

    Reply
    MF
    Marcos FlaTT Mar 26, 2022

    Very good Kevin! Thank you very much for your posting, it solve all my problems!

    MT
    Misha Titkov Apr 30, 2023

    Good afternoon Kevin, thank you for the useful article, but I could not solve my issue with building the application.
    If you have not much time to look at my problem and help me I will be very grateful)
    https://apple.stackexchange.com/questions/459272/chromium-build-no-such-file-not-in-dyld

    DO
    Dob Jun 19, 2023

    `brew reinstall xxxx` with the mentioned library as xxxx solved my specific case.

    Reply