Why doesn't make throw an error when I include some libraries like string.h?

make uses options such as -lcs50 and -lm to link the object files for header file cs50.h and math.h.

For example, the command

make hello

would execute the following:

clang -ggdb -std=c99 -Wall -Werror hello.c -lcrypt -lcs50 -lm -o hello

But when I included string.h, I was expecting it to throw an error assuming that, by default, it doesn't link string.h. However, it got compiled successfully!

Can anyone explain me the reason behind that?


First, .h files are not libraries. Rather, they're libraries' header files. More on that here! The string library, as @Hassan Javed said, is part of the C standard library. And it's linked by default. Libraries that are not part of the C standard library (e.g., the cs50 library) need to be linked manually with the -l flag.

  • Hi Kareem. Thanks for answering the query. As you mentioned most header files like string.h ctype.h stdio.h are already part of C standard library. Also, cs50.h is written by CS50 teaching staff, so it is not a part of "C standard library". But I don't understand, why math.h is left out of the same. Jul 13 '14 at 3:25
  • 1
    @HimanshuChawla unfortunately, the math library, though part of the C standard library, it's implemented in a separate .a file and it's not linked by default for historical reasons. You may have a look at this question for more information!
    – kzidane
    Jul 13 '14 at 13:23
  • Thanks @Kareem for answering my query and pointing me to the reference link. It was very helpful. Jul 16 '14 at 16:09
  • @HimanshuChawla you're welcome! :) you may vote the answer up and accept it if it was helpful! Thank you!
    – kzidane
    Jul 16 '14 at 16:33
  • @Kareem What about the stdlib.h? Is it part of C standard library or is there a flag for it? Jan 29 '15 at 23:08

String.h is a part of the C standard library. So it is automatically linked by the compiler without setting a -lstring flag.This is why you don't see an error.

You must log in to answer this question.

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