Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

Compiler Command-Line Driver
2012-2013 Microchip Technology Inc. DS50002071C-page 77
5.3.2 Single-Step Compilation
A single command-line instruction can be used to compile one file or multiple files.
5.3.2.1 COMPILING A SINGLE FILE
This section demonstrates how to compile and link a single file. For the purpose of this
discussion, it is assumed the compiler is installed in the standard directory location and
that your PATH or other environment variables (see Section 5.2.2 Environment Vari-
ables) are set up in such a way that the full compiler path need not be specified when
you run the compiler.
The following is a simple C program that adds two numbers.
Create the following program with any text editor and save it as ex1.c.
#include <xc.h>
int main(void);
unsigned int Add(unsigned int a, unsigned int b);
unsigned int x, y, z;
int
main(void)
{
x = 2;
y = 5;
z = Add(x,y);
return 0;
}
unsigned int
Add(unsigned int a, unsigned int b)
{
return(a+b);
}
The first line of the program includes the header file xc.h, which will include the appro-
priate header files that provides definitions for all special function registers on the target
device. For more information on header files, see Section 6.3 Device Header Files.
Compile the program by typing the following at the prompt in your favorite terminal.
xc16-gcc -mcpu=30f2010 -o ex1.elf ex1.c
The command-line option -o ex1.elf names the output executable file (if the -o
option is not specified, then the output file is named a.out). The executable file may
be loaded into the MPLAB X IDE or MPLAB IDE v8.
If a hex file is required, for example, to load into a device programmer, then use the
following command:
xc16-bin2hex ex1.elf
This creates an Intel hex file named ex1.hex.

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh