2.7.1 Creating a Generic Library

A generic library may be created that contains multiple versions of the same function(s), compiled for different device families.

For example, let us assume you wish to create a library that will work on both dsPIC33AK and dsPIC33EP devices. The library will be called foo and is based on a single source file called lib.c. Since the two device families are based on different CPU architectures, two different object files must be created. The procedure for creating a generic library would be as follows:

  1. Compile lib.c for each target device family and specify a unique name for each object file.
  2. Using the archiver/librarian tool, combine the two object files into a library file. Here are the specific commands needed to create the generic library file:
    xc-dsc-gcc -c lib.c -mcpu=GENERIC-32DSP-AK -o libc.ak.o
    xc-dsc-gcc -c lib.c -mcpu=GENERIC-16DSP-EP -o libc.ep.o
    xc-dsc-ar cvq libfoo-elf.a libc.ak.o libc.ep.o

Note 1: Object file names must be unique, but do not have to end with '.o'

Note 2: The general format of a library file name is lib<name>{-elf}.a. It is safe to omit -elf, but if you want the library to be compatible with XC16 it is best to include it. The -lfoo linker option will direct the linker to locate and load file libfoo{-elf}.a.

When a project containing library 'foo' is built, the linker will automatically include the appropriate object file based on its signature.

Note 3: A list of supported devices, as well as generic device family names, may be found in section 4 of Readme_XC32.html.