Using the Standard C and Math Libraries

Building an application which utilizes the standard C and math libraries requires two types of files: header files and library files.

Header Files

All standard C library entities are declared or defined in one or more standard headers. To make use of a library entity in a program, write an include directive that names the relevant standard header.

The contents of a standard header is included by naming it in an include directive, as in:

#include <stdio.h> /* include I/O facilities */

The standard headers can be included in any order. Do not include a standard header within a declaration. Do not define macros that have the same names as keywords before including a standard header.

A standard header never includes another standard header.

Library Files

The archived library files contain all the individual object files for each library function.

When linking an application, the library file must be provided as an input to the linker (using the --library or -l linker option) such that the functions used by the application may be linked into the application.

A typical C application will require these library files: libc-omf.a and libpic30-omf.a (see “Libraries Overview, OMF-Specific Libraries and Startup Modules” for more on OMF-specific libraries). These libraries will be included automatically if linking is performed using the compiler.

Note: Some standard library functions require a heap. These include the standard I/O functions that open files and the memory allocation functions. See the “MPLAB® XC16 Assembler, Linker and Utilities User’s Guide” (DS52106) and “MPLAB® XC16 C Compiler User’s Guide” (DS00052071) for more information on the heap.