3.2.5 How Do I Build Libraries?
Use the librarian,
, to build libraries from p-code (.p1) or
object (.o) modules. Libraries can contain any mix of these module
types, but C source code to be placed into a library should always be pre-built into a
p-code module. Object modules should only be used for assembler source. See 4.2.3 Multi-Step C Compilation for information on
building p-code files and 8.1 Archiver/Librarian for the librarian options.xc8-ar
For example:
xc8-cc -mcpu=16f877a -c lcd.c utils.c io.c
xc8-ar -r myLib.a lcd.p1 utils.p1 io.p1
creates a library file called myLib.a.
The MPLAB X IDE allows you to create a library project that will build a library file as the final output. Select Library Project from the Microchip Embedded Category when creating a new project to create a library of your source code.
Note that if you intend to step through your library code at a C level in MPLAB X IDE, you will need to place the library source files so that the relative path between their location and the project that is using them is the same as the relative path between where the library build command was executed and where the source files were located when they were built.