The header files only include the definition of the functions that you would use in a file where the header file is being included.
Library files comprise the actual implementation of the functions that you will be using in your program.
The header file is included (copy/pasted) during the preprocessing stage and is compiled as part of the program being written during compilation phase. One has to specify the -lpthread in the command line, so that the linker will know which library to look into for functions used in the program.
Similar Question/Answer on Stackoverflow explaining it in layman terms:
What's the difference between a header file and a library?
Part 2: Why we do not have to always include library files when we have #include
?
This might be the case when:
i. The implementation of the
functions is included in the header
file.
ii. The implementation of the
functions is in c
files for which
you have the source available.
iii. The required libraries are
included by your compiler by default
e.g., standard c libraries.
NOTE: Here is a reference to what is included in the standard C library, which is included by default by many compilers.