C Programming Library Files and Header Files

Last modified by Microchip on 2023/11/09 09:06

Example

Graphic showing LibFile.h and  LibFile.c in Main.c

In this example, LibFile.c could represent any library file, whether it is included with the compiler (such as ADC.c, USART.c, etc.) or one of your own making. The header file, LibFile.h, contains the extern variable declarations and function prototypes that will be required by any program that wants to access the variables and functions contained in LibFile.c. So, if we include LibFile.h into our program Main.c and we add the file LibFile.c to our project, Main.c will have access to any variable or function in LibFile.c that is declared in the header file LibFile.h.

Note that LibFile.c could be replaced with a pre-compiled object file such as LibFile.o or a library (archive) file that may contain many related precompiled source files such as LibFile.lib (C18 and most non-GNU compilers) or LibFile.a (C30 and all GNU-based compilers).