cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.74k stars 853 forks source link

macOS Mojave compiling issue #158

Closed meliodaseren closed 5 years ago

meliodaseren commented 5 years ago

Local machine: macOS Mojave 10.14.3

After the installation (v9.0.0) is complete, I execute the following command for compiling: gcc -lcs50 hello.c

But the log shows the following error:

ld: library not found for -lcs50
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have checked /usr/local and there do have the following files after installation: /usr/local/lib/libcs50-9.0.0.dylib /usr/local/lib/libcs50.dylib /usr/local/include/cs50.h

What can I do to check this issue ?

intrueder commented 5 years ago

@meliodaseren try this command gcc -lcs50-9.0.0 hello.c

mattangriffel commented 5 years ago

I had the same error as @meliodaseren and @intrueder's suggestion worked.

mattangriffel commented 5 years ago

It looks like the libcs50.dylib symlink is incorrectly pointing to libcs50-9.dylib for some reason, which I was able to fix by running:

sudo ln -sf libcs50-9.0.0.dylib /usr/local/lib/libcs50.dylib

meliodaseren commented 5 years ago

Hi @intrueder @mattangriffel, it's work, I also modify the symlink of libcs50.dylib, I appreciate your help.

marquelamar commented 5 years ago

@meliodaseren try this command gcc -lcs50-9.0.0 hello.c

THAT was brilliant. Got me up and going again. Man i missed you guys. Hope i can finish this course this time. Wish me luck. Blessings! (i actually used -lcs50-9.0.1, in case anyone was wondering)

MMusashi97 commented 2 years ago

error - cc hello2.c -o hello2 Undefined symbols for architecture arm64: "_get_string", referenced from: _main in hello2-1413d6.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [hello2] Error 1

rongxin-liu commented 2 years ago

error - cc hello2.c -o hello2 Undefined symbols for architecture arm64: "_get_string", referenced from: _main in hello2-1413d6.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [hello2] Error 1

Besure to link CS50 C library when compiling your program:

clang example.c -lcs50 -o example

MMusashi97 commented 2 years ago

Thank you, this three part youtube video is also very helpful https://krishanthecoder.io/installing-cs50-library-locally-on-macos/

lentil32 commented 9 months ago

lenntil/cs50-minimal-setup: CS50 Minimal Setup for macOS and Linux

I wrote this to help you guys.