Create a Library Project

1

Launch the new project wizard

Toolbar: Main_New_Project.png
Keyboard: Ctrl+Shift+N
Menu: File > New Project…

2

Choose Project Type

Choose Library Project from the list on the right and click Next >.

This will create a project that will generate a library file (*.lib or *.a depending on which compiler you use) instead of a hex file. This project will not be able to run on its own as it will not have a main() function. The resulting library will be used in another project that has its own main() function.

mylib_1.png
Click image to enlarge.

3

Select Device

Select the device family and device that are in the same family for which you wish to use this library. Click Next >.

As a general rule, libraries may be used on any device that shares the architecture of its original target. In this example, we are choosing a PIC24FJ128GA010 because it is a fairly generic "superset" device that has a little bit of everything that the PIC24F family has to offer. This doesn't mean that we can only use this library with this device. On the contrary, we should be able to use it with any PIC24F device as long as we don't use some feature that is unique to the PIC24FJ128GA010. The key is that if our library references any on chip hardware by its register names, this library may only be used with devices whose registers share the same names. The reason this works is because this library project will not be linked. So, register names will NOT be equated to their hardware addresses. Rather they are left "floating" until this library is used in a different, standalone project where the linker will finally connect the names used here to the hardware addresses of the standalone project's target device.

mylib_2.png
Click image to enlarge.

4

Select Header

Leave this checkbox unchecked. This only affects debugging, which cannot be done directly with a library project. Click Next >.

mylib_3.png
Click image to enlarge.

5

Select Tool

Since a library project cannot be debugged on its own, choose nothing or choose the simulator. It really doesn't matter. Click Next >.

mylib_4.png
Click image to enlarge.

6

Select Compiler

Choose the appropriate compiler or assembler for your target architecture. Click Next >.

The choice of compiler here not only determines which tool will build the object files for the library, but also determines which compiler this library may be used with when included in other projects. However, you are not tied down to a particular version number in most circumstances. For example, if I choose the XC16 compiler, I cannot use this library with Hi-Tech, CCS, nor any other compiler that supports this device family, but I should be able to use it with subsequent versions of the XC16 compiler.

Libraries may also be written in and used in assembly language, but they must be written as relocatable code. If you wish to mix assembly and C, then assembly libraries must be written to be both relocatable and C callable. This requires a thorough understanding of your compiler's parameter passing conventions.

mylib_5.png
Click image to enlarge.

7

Select Project Name and Folder

Choose a name and location for your project. Click Finish.

The name you give your project will be the name of the library file it generates. In this example the project name is MyLib and the library file it generates will be MyLib.x.a. The ".a" suffix is the library suffix used by XC16 and XC32. The ".x" is automatically inserted to indicate that this library was built using the MPLAB® X IDE. The name isn't critical and you can always change the name of the generated library file in your file manager before using it in another project.

mylib_6.png
Click image to enlarge.
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.