In the video of compiler, we have to link the math library with hello.o
with with the -lm
flag. Why don't we have to link stdio library with hello.o
?
2 Answers
because, unlike the math library, the standard library is linked by default unless you tell the compiler that you don't want that to happen, which isn't usually what you need.
Explicitly linking of library is only needed if you are using a non-standard library in your program such as math.h and cs50.h. Standard libraries such as stdio.h, stdlib.h, string.h, ctype.h etc. are by default linked in the linking step in the compilation process. Hope this answers your question.