7.2.3 Multi-Step Compilation
Make utilities and integrated development environments, such as MPLAB IDE, allow for an incremental build of projects that contain multiple source files. When building a project, they take note of which source files have changed since the last build and use this information to speed up compilation.
For example, if compiling two source files, but only one has changed since the last build, the intermediate file corresponding to the unchanged source file need not be regenerated.
If the compiler is being invoked using a make utility, the make file will need to be configured to recognize the different intermediate file format and the options used to generate the intermediate files. Make utilities typically call the compiler multiple times: once for each source file to generate an intermediate file and once to perform the second stage compilation.
You may also wish to generate intermediate files to construct your own library files, although MPLAB XC16 is capable of constructing libraries so this is typically not necessary. See MPLAB® XC16 Assembler, Linker and Utilities User’s Guide (DS50002106) for more information on library creation.
For example, the files ex1.c
and add.c
are to be compiled using a make utility. The command lines that the make utility should
use to compile these files might be something like:
xc16-gcc -mcpu=30f6014 -c ex1.c
xc16-gcc -mcpu=30f6014 -c add.c
xc16-gcc -mcpu=30f6014 -o ex1 ex1.o add.o
The -c
option will compile the named file into the
intermediate (object) file format, but not link. Once all files are compiled as
specified by the make, then the resultant object files are linked in the final step to
create the final output ex1
. The above example uses the command-line
driver, xc16-gcc
, to perform the final link step. You can explicitly
call the linker application, xc16-ld, but this is not recommended. When driving the
linker application, you must specify linker options, not driver options. For more on
using the linker, see MPLAB® XC16 Assembler,
Linker and Utilities User’s Guide (DS50002106).
When compiling debug code, the object module format (OMF) must be
consistent for compilation, assembly and linking. The ELF/DWARF format is used by
default but the COFF format may also be selected using -omf=coff
or the
environmental variable XC16_OMF
.