cs50 / libcs50

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

Issue while running on Apple silicon #324

Open forestpurnell opened 3 months ago

forestpurnell commented 3 months ago

Hello, after an error-free compile and install, the first time I try to compile a program with the libcs50 headers, I get this error:

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

Is there some reason this wouldn't be able to run on an arm64 mac?

T1To48 commented 2 months ago

so simple i ran into this issue with my M2

just run the command like this cc runoff.c -lcs50 -o runoff because you need to link the cs50 library with the c compiler

sufyazi commented 2 months ago

Hi I faced the same problem. Can you elaborate what runoff.c is from and what is this doing explicitly?

sufyazi commented 2 months ago

Hi I faced the same problem. Can you elaborate what runoff.c is from and what is this doing explicitly?

Never mind, I figured it out. I just need to specify the source code file I am trying to make and the output, so in my case, it's mario.c and mario for the -o flag.

I wonder if this links the library to the compiler for all future invocations or just once and I would have to do this for every other source code files I have.

T1To48 commented 2 months ago

no it didnt link, each time i should run the command with -lcs50, but i think if u want it to be linked permenantly something should be added to the .zshrc or .bashrc depends on the CLI you are using..

T1To48 commented 2 months ago

Hi I faced the same problem. Can you elaborate what runoff.c is from and what is this doing explicitly?

Never mind, I figured it out. I just need to specify the source code file I am trying to make and the output, so in my case, it's mario.c and mario for the -o flag.

I wonder if this links the library to the compiler for all future invocations or just once and I would have to do this for every other source code files I have.

am at mario at the moment too! which version R u submitting the less OR more?

sufyazi commented 2 months ago

Hi I faced the same problem. Can you elaborate what runoff.c is from and what is this doing explicitly?

Never mind, I figured it out. I just need to specify the source code file I am trying to make and the output, so in my case, it's mario.c and mario for the -o flag. I wonder if this links the library to the compiler for all future invocations or just once and I would have to do this for every other source code files I have.

am at mario at the moment too! which version R u submitting the less OR more?

I am still following through the Section part of Week 1, so I am not aware of or familiar with what 'less OR more' problem you are talking about, sorry.

I tried modifying my zshrc dotfile though based on the README but nothing happened; my compiler doesn't see the custom library. I had to copy and paste the .dylib file to my working directory for my code to compile.

T1To48 commented 2 months ago

try adding this :

export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH

to the .zshrc and remove what you have previously added.

T1To48 commented 2 months ago

Assuming u have installed the libcs50 in its default location and didnt use custome install location for the cs50 library

diegovskytl commented 1 month ago

@T1To48 @sufyazi @forestpurnell did any change to the environment variables helped with that issue? It seems that the default version for Make in MacOS is 3.18, a bit old. I wonder if that is part of the issue. Edit: It seems it should not be an issue; should be solved by modifying environment.

T1To48 commented 1 month ago

@diegovskytl mine works perfectly fine, but i dont run commands with make i use :

cc filename.c -lcs50 -o filename