I'm following along with the Harvard cs50 lectures. Using a mac OS, I have downloaded VirtualBox, and installed cs50 library from https://manual.cs50.net/CS50_Library (I typed the Linux, Fedora code into the terminal in gedit). However I still cannot seem to use the functions when I have #include <cs50.h> after compiling
I get undefined reference to "GetString"
When you compile, just tell your compiler to look in the local directory where the header is. The #include with angle brackets (<>) searches in the compiler's include directory by default, and your file is not there.
In gcc (and I would try with other compilers) you have to add:
but in different compilers there are different switches, so you should double check. If you still get "undefined reference" linker errors, then -I is not the switch.
Also you must tell the linker to link with the proper library. Undefined reference errors usually mean the linker can not find the function implementations. Normally if the compiler can not find the include file the error message would be about function not being declared.
Thanks both for your reply.
In terminal I am typing gcc name.c -I"user/local/lib/cs50.h" and am still getting undefined reference error.
I have only written a hello world with the stdio.h so I am very new
Is the stdio.h stored in the computer, where I can but the cs50.h file there too?
Do you only have the library header? You also have to link against code.
Precompiled libraries will have the extension .a or .so, or .lib on windows. If you find those, you need to link them with -l (ell) like jim said. If you put it in the -I directory then you shouldn't have a problem.
If you have a C file with library code, all you have to do is add it to your project.
I don't think a teacher would provide just a header, so you need to double check that you have everything you need. But at the moment you're stuck.