I am doing the CS50 class, I have installed the cs50.h.
Based on the instructions I used the following command in terminal to compile my simple program and just want to make sure I understand everything im asking terminal to do.
Line is:
gcc -g hello.c -o hello -lcs50 -lm
I know the following*: gcc =
- gcc = gnu compiler for C
- -g = generate source-level debug information
- Hello.c = name of the file we want to compile
- -o = write output file
- hello = our output file name
Can anyone tell me what -lcs50 and -lm are? My guess is that its calling on the library lcs50 in (-lcs50) but again this is a guess and would like to know for sure.
Everything works as it should with no issues
Thanks,
>Solution :
Mostly correct.
-
-ois not required to generate the output file, it’s only needed to customize the name. (-oand the following name can only appear together). -
-lcs50means "link the library calledcs50", notlcs50. It will try to find this file using several different name patterns, e.g.libcs50.so(on Linux),[lib]cs50.dll[.a](on Windows),libcs50.a(on both), something else on Mac. -
-lmlinks the standard math library, but I don’t think you need to manually specify it on most modern GCC distributions.