18 Library Routines
Many library functions or routines (and any associated variables) will be automatically linked into a program once they have been referenced in your source code. The use of a function from one library file will not include any other functions from that library. Only used library functions will be linked into the program output and consume memory.
Library and precompiled object files are stored in the compiler’s installation directory structure.
Your program will require declarations for any functions or symbols used
from libraries. These are contained in the standard header files for C
(.h) or C++ (.hpp) . Header files are not library
files and the two files types should not be confused. Library files contain precompiled
code, typically functions and variable definitions; the header files provide declarations
(as opposed to definitions) for functions, variables and types in the library files, as
well as other preprocessor macros.
The include directories, under the compiler’s
installation directory, are where the compiler stores the standard C library system header
files. The installation will automatically locate its bundled include files.
Some libraries require manual inclusion in your project, or require special options to use. See the following for questions about particular libraries:
- Microchip Unified Standard Library Reference Guide (DS-50003209)
- MPLAB® XC-DSC Libraries Reference Manual for dsPIC33C/E/F and dsPIC30 DSC (DS-50003591)
Libraries which are found automatically include:
- Standard C/C++ library
- Support libraries
- Standard IEEE floating point library
- Fixed point library
Using the Math Library
#include <math.h> // declare function prototype for sqrt
void main(void)
{
double i;
// sqrt referenced; sqrt will be linked in from library file
i = sqrt(23.5);
}
