5.2.2 Multi-Step C Compilation
A multi-step compilation method can be employed to build projects consisting of one or more C source files. Make utilities can use this feature, taking note of which source files have changed since the last build to speed up compilation. Incremental builds are also be performed by integrated development environments, such as the MPLAB X IDE when selecting the Build Project icon or menu item.
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, which links the intermediate files to form the final output. If only one source file has changed since the last build, the intermediate file corresponding to the unchanged source file need not be regenerated.
For example, the files ex1.c and add.c are to be compiled using a make utility. The command lines that the make utility could use to compile these files might be something like:
xc32-gcc
-mprocessor=32MZ2048ECH100 -c ex1.c
xc32-gcc
-mprocessor=32MZ2048ECH100 -c add.c
xc32-gcc
-mprocessor=32MZ2048ECH100 -o ex1.elf ex1.o add.o
The -c
option used with the first two commands will compile the specified
file into the intermediate file format, but not link. The resultant intermediate files are
linked in the final step to create the final output ex1.elf. All the
files that constitute the project must be present when performing the second stage of
compilation.
The above example uses the command-line driver, xc32-gcc
, to perform the final link step. You can explicitly
call the linker application, pic32m-ld
, but this is not recommended as the
commands are complex and when driving the linker application directly, you must specify
linker options, not driver options, as shown above.
For more information on using the linker, see the MPLAB® XC32 Assembler, Linker and Utilities User’s Guide relevant to your project.
You may also wish to generate intermediate files to construct your own library archive files.
See MPLAB® XC32 Assembler, Linker and Utilities User’s Guide relevant to your project for more information on library creation.