I installed the cs50 header files but keep getting this when I run the code.
mallone254 opened this issue · 1 comments
/usr/bin/ld: /tmp/ccPJ5tMn.o: in function main': hello.c:(.text+0x15): undefined reference to
get_long'
/usr/bin/ld: hello.c:(.text+0x2a): undefined reference to `get_long'
collect2: error: ld returned 1 exit status
make: *** [: hello] Error 1
Besure to link CS50 C library when compiling your program:
clang example.c -lcs50 -o example
Also, your make
command doesn't know what static library to include by default, and you likely need to create a proper Makefile if you want to use make
command to compile your program on your own computer. You might want to consult this Makefile tutorial:
https://makefiletutorial.com/
In CS50 Codespace, we have set quite a few environment variables in the terminal and implemented our own make
wrapper to simplify the compilation process:
https://github.com/cs50/cli/blob/main/etc/profile.d/cli.sh#L48-L51
https://github.com/cs50/cli/blob/main/opt/cs50/bin/make