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

Running cs50 in coderunner 4 #271

Closed Willjrs03 closed 1 year ago

Willjrs03 commented 2 years ago

I installed cs50 following the instructions and can't get the function "get_string" or "get_char" to work. I am trying to run cs50 on an external app, in this case coderunner 4

this is what im trying to run

`#include

include

int main(void) { string first= get_string("whats your first name"); string last= get_string("whats your last name"); printf("hello, %s %s\n", first, last); }`

and I get this

LLVM ERROR: Program used external function '_get_string' which could not be resolved!

KAGEYAM4 commented 2 years ago

Did you compiled you .c file along with cs50.c ( note the .c) . the cs50.h just contains the prototype of cs50.c file, so that when your compiler compiles the your_code.c file , it can verify the function call matches to the included cs50.h file so that you don't make mistake and call one less , one more or pass in wrong argument.

The linker job is to link those function call to definition of function in cs50.c because your project only includes your_code.c file , compiler worked but the linked did not.

Google how to compile two or more c files in whatever you using.

for me who just uses terminal , i do this -- g++ your_code.c cs50.c the cs50.c and your_code.c needs to be in same directory or absolute path needs to be mentioned.

Pointabc commented 1 year ago

You can try it. $clang your_code.c -lcs50 And delete ` befor #include .