You need to distinguish between headers and libraries.
Headers declare facilities that are available to programs. When you include a header such as <stdio.h>
(NB: this is not — repeat not! — a library), you make available to the compiler the information necessary to use the facilities from the standard I/O library. In general, C headers do not define the actual code that implements the facilities. C++ has 'header only' libraries (some parts of Boost are prime examples of 'header only' libraries).
Libraries provide the implementation of the facilities. The <stdio.h>
header declares a function fopen()
; there is a library somewhere that defines that function.
Some headers (actually, typically, it is a lot of headers) are privileged and the facilities that they declare are included in the standard library that the C compiler links your programs with. You don't have to do anything special to get the functions linked into your program. Other headers are from libraries that the C compiler does not know about a priori, and for those, you have to tell it where to find the library (e.g. with -L /opt/sometool/lib
as a compiler option) and the library name (e.g. with -lsometool
, which might link with /opt/sometool/lib/libsometool.so
or /opt/sometool/lib/libsometool.a
). Note that the headers for SomeTool are probably in /opt/sometool/include
, and you'd need to add an option -I/opt/sometool/include
to find the sometool.h
header.
The linker doesn't reference headers; the compiler proper doesn't reference libraries. The compiler control program does handle the mixture (it typically runs multiple phases of the compilation process as separate programs — the compiler is separate from the linker). The headers do not contain information about where the library is installed.