libcs50 icon indicating copy to clipboard operation
libcs50 copied to clipboard

Running cs50 in coderunner 4

Open Willjrs03 opened this issue 2 years ago • 1 comments

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 <cs50.h> #include <stdio.h>

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!

Willjrs03 avatar Oct 04 '22 01:10 Willjrs03

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.

KAGEYAM4 avatar Oct 04 '22 08:10 KAGEYAM4

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

Pointabc avatar Dec 26 '22 14:12 Pointabc