Driver Command-line Format

The xc8-cc driver can be used to compile and assemble C and assembly source files, as well as link object files and library archives to form a final program image.

The driver has the following basic command format:

xc8-cc [options] files

So, for example, to compile and link the C source file hello.c, you could use the command:

xc8-cc -mcpu=16F877A -O2 -o hello.elf hello.c

Throughout this manual, it is assumed that the compiler applications are in your console’s search path. See Driver Environment Variables for information on the environment variable that specifies the search locations. Alternatively, use the full directory path along with the driver name when executing the compiler.

It is customary to declare options (identified by a leading dash “-” or double dash “--”) before the files’ names; however, this is not mandatory.

Command-line options are case sensitive, with their format and description being supplied in Option Descriptions. Many of the command-line options accepted by xc8-cc are common to all the MPLAB XC compilers, to allow greater portability between devices and compilers.

The files can be any mixture of C and assembler source files, as well as relocatable object files and archive files. While the order in which these files are listed does not directly affect the operation of the program, it can affect the allocation of code or data. Note, that the order of the archive files will dictate the order in which they are searched, and in some situations, this might affect which modules are linked in to the program.

Note also that the base name of some of the output files is based on the base name of the first C source file listed on the xc8-cccommand line, unless the name is specified using the -o option.

If you are building code using a make system, familiarity with the unique intermediate p-code file format (described in Multi-Step C Compilation), is recommended. Object files are seldom used with the MPLAB XC8 C Compiler, unless assembly source modules are used in the project.