When you include a header
#include "foo.h"
you also need a source file, foo.c
, with the definitions of the prototypes in the header that you pass to the compiler when compiling: gcc main.c foo.c
. Why doesn't the same have to happen for headers from the standard library? For example, say you have a main.c
file with
#include <stdio.h>
when you compile, you don't have to then write gcc main.c stdio.c
, you just write gcc main.c
.
Why is this? Does the compiler/linker know where to look for the source files when you compile and just automatically adds them? If not, then how would the compiler know what to do with the function prototypes?