Microchip Technology SW006021-2 Manuel D’Utilisation
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 94
2012 Microchip Technology Inc.
4.8.2
-D: Define Macro
The -D option is used to define a preprocessor macro on the command line, exactly as
if it had been defined using a #define directive in the source code. This option may
take one of two forms, -Dmacro which is equivalent to:
if it had been defined using a #define directive in the source code. This option may
take one of two forms, -Dmacro which is equivalent to:
#define macro 1
placed at the top of each module compiled using this option, or -Dmacro= text which
is equivalent to:
is equivalent to:
#define macro text
where
text
is the textual substitution required. Thus, the command:
xc8
--CHIP=16F877AA -Ddebug -Dbuffers=10 test.c
will compile test.c with macros defined exactly as if the C source code had included
the directives:
the directives:
#define debug 1
#define buffers 10
Defining macros as C string literals requires bypassing any interpretation issues in the
operating system that is being used. To pass the C string, "hello world", (including
the quote characters) in the Windows environment, use: "-DMY_STRING=\\\"hello
world\\\""
operating system that is being used. To pass the C string, "hello world", (including
the quote characters) in the Windows environment, use: "-DMY_STRING=\\\"hello
world\\\""
(you must include the quote characters around the entire option as there
is a space character in the macro definition). Under Linux or Mac OS X, use:
-DMY_STRING=\"hello\ world\"
-DMY_STRING=\"hello\ world\"
.
See Section 4.9 “MPLAB IDE V8 Universal Toolsuite Equivalents” or
Section 4.10 “MPLAB X Universal Toolsuite Equivalents” for use of this option in
MPLAB IDE.
Section 4.10 “MPLAB X Universal Toolsuite Equivalents” for use of this option in
MPLAB IDE.
4.8.3
-E: Redirect Compiler Errors to a File
This option has two purposes. The first is to change the format of displayed messages.
The second is to optionally allow messages to be directed to a file as some editors do
not allow the standard command line redirection facilities to be used when invoking the
compiler.
The second is to optionally allow messages to be directed to a file as some editors do
not allow the standard command line redirection facilities to be used when invoking the
compiler.
The general form of messages produced with the -E option in force is:
filename line_number: (message number) message string (type)
If a filename is specified immediately after -E, it is treated as the name of a file to which
all messages (errors, warnings, etc.) will be printed. For example, to compile x.c and
redirect all errors to x.err, use the command:
all messages (errors, warnings, etc.) will be printed. For example, to compile x.c and
redirect all errors to x.err, use the command:
xc8
--CHIP=16F877AA -Ex.err x.c
The -E option also allows errors to be appended to an existing file by specifying an
addition character, +, at the start of the error filename, for example:
addition character, +, at the start of the error filename, for example:
xc8
--CHIP=16F877AA -E+x.err y.c
If you wish to compile several files and combine all of the errors generated into a single
text file, use the -E option to create the file then use -E+ when compiling all the other
source files. For example, to compile a number of files with all errors combined into a
file called project.err, you could use the - E option as follows:
text file, use the -E option to create the file then use -E+ when compiling all the other
source files. For example, to compile a number of files with all errors combined into a
file called project.err, you could use the - E option as follows:
xc8
--CHIP=16F877AA -Eproject.err -O --PASS1 main.c
xc8
--CHIP=16F877AA -E+project.err -O --PASS1 part1.c
xc8
--CHIP=16F877AA -E+project.err -C asmcode.as
Section 4.6 “Compiler Messages” has more information regarding this option as well
as an overview of the messaging system and other related driver options.
as an overview of the messaging system and other related driver options.