|
|
|||||||
|
In normal operation, our standard compilers compile C and assembler source files into object files, and then link those object files together, along with the system libraries, to produce Hex and COFF files which you use to program your chip. Sometimes you might want to create your own library files. We have long provided the LIBR tool to manipulate library files, but now (that is, since version 9.50 of our PIC-family compilers) there's an easier way: use --output=LIB on the command line of the Link phase to create a library file instead of a Hex or COFF file. To illustrate how this would be used in practice, consider an MPLAB project called App with a number of source files where some of these source files are used across multiple projects - say, the code to control an LCD display.
It's important to remember that library files are only searched for functions and variables actually referenced from source files within your project, so you should ensure that your main() function and any interrupt service routines are not put into a library. Note also that both the library and any application you link it with must be built with the same compiler options. Some option mismatches can be caught by the linker (e.g. differences in double width, and possibly code-pointer size) but not all of them can, and the diagnostic messages for those that are detected won't necessarily say "build option mismatch between library and application". |
||||||||
|
|
|||||||
|
Thank you for the excellent tips. Does a library have to include a "main" function? Or is the missing main due to the MPLAB IDE? I made an empty main.c just to make it happy. Do I need to make a library for each device type? Or can it be a generic PIC18F as long as it is not doing I/O? I am writing test cases using the simulator for my library routines. Is it possible to source level debug into a library routine? Thanks, -Ed |