dyld: library not loaded. no such file

1.8k Views Asked by At
h@Hrvojes-MacBook-Pro problemSet2 % ./hours                      
dyld[18659]: Library not loaded: libcs50-11.0.2.dylib
  Referenced from: <099E85B4-69E7-3DB9-BBCB-261540A924DC> /Users/h/CS50 Learning/2.ARRAYS/problemSet2/hours
  Reason: tried: 'libcs50-11.0.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcs50-11.0.2.dylib' (no such file), 'libcs50-11.0.2.dylib' (no such file), '/Users/h/CS50 Learning/2.ARRAYS/problemSet2/libcs50-11.0.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/h/CS50 Learning/2.ARRAYS/problemSet2/libcs50-11.0.2.dylib' (no such file), '/Users/h/CS50 Learning/2.ARRAYS/problemSet2/libcs50-11.0.2.dylib' (no such file)
zsh: abort      ./hours

I tried running a simple program I wrote and it's not compiling.

2

There are 2 best solutions below

1
Oka On

You need to install, and/or locate, the dynamic library it is looking for: libcs50


The instructions for installing on mac OS are (copied from README.md):

From Source (Linux and Mac)

  1. Download the latest release from https://github.com/cs50/libcs50/releases
  2. Extract libcs50-*.*
  3. cd libcs50-*
  4. sudo make install

By default, we install to /usr/local. If you'd like to change the installation location, run sudo DESTDIR=/path/to/install make install as desired.


Afterwards, recompile your program (link with -lcs50).

If you are still having trouble, ensure you are looking for the dynamic libraries in the correct place by using the LD_LIBRARY_PATH environment variable.

With the default install from above, execute your program as:

$ LD_LIBRARY_PATH=/usr/local/lib ./hours

(If you installed with a different path, i.e., you used DESTDIR above, then specify that path for LD_LIBRARY_PATH.)

0
user23739193 On

It's quite simple to fix that little issue. First execute the following command

find / -name "libcs50-11.0.2.dylib"

Once "find" finishes his search use the "mv" command to rename the files

 mv /path/to_file/"libcs50-11.0.2.dylib" /path/to_file/libcs50_11_0_2.dylib

Notice the underscores you can even not put them at all like this

mv /path/to_file/"libcs50-11.0.2.dylib" /path/to_file/libcs501102.dylib

As final step try to run your program again.