6.2.3 Multi-Step Compilation
Make utilities and integrated development environments, such as MPLAB X 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 XC-DSC is capable of constructing libraries so this is typically not necessary. See “MPLAB® XC-DSC Assembler, Linker and Utilities User’s Guide” (DS-50003590) 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:
xc-dsc-gcc -mcpu=33EP32MC504 -c
ex1.c
xc-dsc-gcc -mcpu=33EP32MC504 -c
add.c
xc-dsc-gcc -mcpu=33EP32MC504 -o
ex1 ex1.o add.o -T p33EP32MC504.gld
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, xc-dsc-gcc
, to perform the final
link step. You can explicitly call the linker application, xc-dsc-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® XC-DSC
Assembler, Linker and Utilities User’s Guide” (DS-50003590).