6.1 Operation

A command to the linker takes the following form:
hlink [options] files

The options are zero or more case-insensitive linker options, each of which modifies the behavior of the linker in some way. The files is one or more object files and zero or more library files (.a extension).

The options recognized by the linker are listed in the table below and are discussed in the paragraphs that follow.

Table 6-1. Linker Command-line Options
OptionEffect
-Aclass=low-high ,...Specify address ranges for a class.
-Cpsect=classSpecify a class name for a global psect.
-CtypeSpecify call graph type.
-Dclass=deltaSpecify a class delta value.
-DsymfileProduce old-style symbol file.
-EerrfileWrite error messages to errfile.
-FProduce .o file with only symbol records.
-G specSpecify calculation for segment selectors.
-H symfileGenerate symbol file.
-H+ symfileGenerate enhanced symbol file.
-IIgnore undefined symbols.
-J numSet maximum number of errors before aborting.
-KPrevent overlaying function parameter and auto areas.
-LPreserve relocation items in .o file.
-LMPreserve segment relocation items in .o file.
-MmapfileGenerate a link map in the named file.
-NSort symbol table in map file by address order.
-NcSort symbol table in map file by class address order.
-NsSort symbol table in map file by space address order.
-OoutfileSpecify name of output file.
-PspecSpecify psect addresses and ordering.
-QprocessorSpecify the device type (for cosmetic reasons only).
-SInhibit listing of symbols in symbol file.
-Sclass=limit[,bound]Specify address limit, and start boundary for a class of psects.
-UsymbolPre-enter symbol in table as undefined.
-VavmapUse file avmap to generate an Avocet format symbol file.
-WwarnlevSet warning level (-9 to 9).
-WwidthSet map file width (>=10).
-XRemove any local symbols from the symbol file.
-ZRemove trivial local symbols from the symbol file.
--DISL=listSpecify disabled messages.
--EDF=pathSpecify message file location.
--EMAX=numberSpecify maximum number of errors.
--fixupoverflow=actionSpecify response when encountering fixup overflows.
--NORLFDo not relocate list file.
--VERPrint version number and stop.
--werror=numPromote warnings to errors
If the standard input is a file, then this file is assumed to contain the command-line argument. Lines can be broken by leaving a backslash \ at the end of the preceding line. In this fashion, hlink commands of almost unlimited length can be issued. For example, a link command file called x.lnk and containing the following text:
-Z -Ox.o -Mx.map \
-Ptext=0,data=0/,bss,nvram=bss/. \
x.o y.o z.o
can be passed to the linker by one of the following:
hlink @x.lnk
hlink < x.lnk

Several linker options require memory addresses or sizes to be specified. The syntax for all of these is similar. By default, the number is interpreted as a decimal value. To force interpretation as a HEX number, a trailing H, or h, should be added. For example, 765FH will be treated as a HEX number.

To build projects you will typically use either the MPLAB XC8 C compiler (xc8-cc) driver or the MPLAB XC8 PIC Assembler (pic-as) driver. These will call the linker for you, passing it a set of default linker options. If you need to modify or supply additional linker options when using a driver, use either the -Wl (see Wl: Pass Option To The Linker, Option) or -Xlinker (see Xlinker Option) driver options, which will pass on the suboption to the linker application when it is executed.