Building XC8 Libraries

Recent versions of MPLAB® X IDE now allow you to create library projects for the MPLAB XC8 Compiler. The process of creating and building a library project for this compiler is the same as that for the other MPLAB XC compilers, and that process is discussed in the article here. There are, however, a few subtle differences between the libraries produced by MPLAB XC8 and those of the other Microchip compilers. These differences are discussed in this article.

MPLAB XC8 library files use their own format, which is different to that produced by the other MPLAB XC compilers and which is also different to that used by the legacy MPLAB C18 compiler. MPLAB XC8 libraries use the extension .lpp. Do not rename or specify these files to use any other extension, such as .lib. The IDE will produce a library with the correct extension when you build a library project. If your project is called MyLib, the output library file will be called MyLib.X.lpp.

The LPP libraries built by MPLAB XC8 must be built from only C source files. Libraries built from assembly code must be encoded in a different format, must use the traditional .lib extension, and they must be built by the compiler on the command line. You cannot build any library from a mix of C and assembly source.

When you are using a library built with MPLAB XC8, you can perform C-level debugging (e.g. C-line stepping, watching variables etc.,) on the routines and variables defined in the library routines, provided the original source code for the library is available and in the correct location. 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. Assuming that you built the library from source files that were placed into the library’s .X project directory, then you simply need to copy the source files into the .X directory of the project that is using the library for debugging to work correctly. If the source files are not available, the library code will still work as expected, but you will lose the ability to debug the library routines.

Although you can now easily build libraries from within MPLAB X IDE, you can continue to build libraries on the command line using the XC8 compiler if you prefer. This can be performed in just one step. For example, to build the source code contained in adc.c, lcd.c, and init.c into a library, the following command line will perform this task.

xc8 --chip=18f4520 --output=lpp init.c adc.c lcd.

This will create an output called init.lpp, which you can rename, if required. Alternatively, you can specify an output file name using the compiler’s -O option, for example, -OMyLib.lpp.

© 2017 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.