0

I have a very slow internet connection (computer too for that matter) and thus have been trying to use CS50 library locally. I download the source files from: https://github.com/cs50/libcs50/ and put both cs50.h and cs50.c in my project directory. Everything seems to work fine until I compress. GCC gives me this error message:

C:\Users\{user-name}\AppData\Local\Temp\cclUSb5a.o:plurality.c:(.text+0xe7): undefined reference to `get_int'
C:\Users\{user-name}\AppData\Local\Temp\cclUSb5a.o:plurality.c:(.text+0x110): undefined reference to `get_string'
collect2.exe: error: ld returned 1 exit status

I use VS Code and when I went to check the cs50.h header file, it says it expected "{" in between what seems like two function declarations.

char get_char(const char *format, ...) __attribute__((format(printf, 1, 2)));

I checked GitHub. Someone submitted an issue concerning this; it hasn't been fixed yet.

I have basic very basic knowledge of C and I have no idea how to fix this syntax error(?). I was hoping if someone could solve this. Thanks in advance!!

  • 1
    "until I compress" -- did you mean "until I compile"? – Barmar Aug 28 '20 at 11:33
  • There's no `{` anywhere in `cs50.h`. Are you sure that error is about `cs50.h`, not `cs50.c`? – Barmar Aug 28 '20 at 11:34
  • 1
    The undefined reference error is because you didn't link with `cs50.o`. – Barmar Aug 28 '20 at 11:34
  • @Barmar 1. Yes, that was a stupid mistake. 2. There's no `{` but VS Code says it expects one in between; I for one have no clue as to why. 3. I didn't know about the linking. After running `gcc pluraity.c cs50.c`, it worked as expected. Thank you very much!! – karuifeather Aug 28 '20 at 12:44
  • See https://github.com/microsoft/vscode-cpptools/issues/4787 vscode apparently has problems with attributes. – Barmar Aug 28 '20 at 13:55
  • Oh I see. Thanks again! – karuifeather Aug 28 '20 at 19:23

0 Answers0