-1

I just began CS50 and was trying to copy some of the examples done on the lecture video. I use opensuse tumbleweed(also a little new to it) and I had installed the cs50 c library just as the documentation asked. My code is:

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    string answer = get_string("What's your name?");
    printf(answer);
}

and I get an error that is this in my terminal:

/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: /tmp/cciFW8gc.o: in function `main':
hello.c:(.text+0x18): undefined reference to `get_string'
collect2: error: ld returned 1 exit status

I get this error whether I run it in my vscode or terminal and am not sure whether I installed the library incorrectly or included it wrong. I did further testing and saw that "string" works and I understand that is also a part of the library, so I guess the issue is with get_string. Any help is appreciated!

1
  • You need to link the cs50 library with -l switch when compiling. Maybe this helps Commented Jan 7, 2022 at 13:34

1 Answer 1

0

I know I might be late and I would like to hear if you were able to solve this issue, but I faced same exact one on Debian Testing. I have CS50 library installed via make install from official GitHub repo.

The directory with library in question is in LIBRARY_PATH, but I'm still getting same error message trying compile Hello program. So, I've used clang:

clang -lcs50 -o hello hello.c

where:

  • -lcs50 is a library (-l) to compile against (cs50 is called libcs50.so., it picks the library without the need to specify it's full file name
  • -o hello is the file name to which the output will be written
  • hello.c is the source code file(s).

Hope that'll help some new people doing this course on their own Linux boxes to get it to work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .