Node:GPC Options, Previous:GPC Command Line Options, Up:Invoking GPC
As the most simple example, calling
gpc foo.pas
tells GPC to compile the source file foo.pas
and to produce
an executable of the default name which is foo.exe
on EMX,
a.exe
on Cygwin, both a.out
and a.exe
on DJGPP,
and a.out
on most other platforms.
Users familiar with BP, please note that you have to give the file
name extension .pas
: GPC is a common interface for a Pascal
compiler, a C, ObjC and C++ compiler, an assembler, a linker, and
perhaps an Ada and a FORTRAN compiler. From the extension of your
source file GPC figures out which compiler to run. GPC recognizes
Pascal sources by the extension .pas
, .p
, .pp
or .dpr
. GPC also accepts source files in other languages
(e.g., .c
for C) and calls the appropriate compilers for
them. Files with the extension .o
or without any special
recognized extension are considered to be object files or libraries
to be linked.
Another example:
gpc -O2 -Wall --executable-file-name --automake --unit-path=units foo.pas
This will compile the source file foo.pas
to an executable
named foo
(--executable-file-name
) with fairly good
optimization (-O2
), warning about possible problems
(-Wall
). If the program uses units or imports modules, they
will be searched for in a directory called units
(--unit-path
) and automatically compiled and linked
(--automake
).
The following table lists the most commonly used options to GPC.
--automake
--unit-path=dir[:dir...]
--object-path=dir[:dir...]
--unit-destination-path=dir
--object-destination-path=dir
--unit-destination-path
.
--executable-path=dir
-o file
Since only one output file can be specified, it does not make sense
to use -o
when compiling more than one input file, unless you
are producing an executable file as output.
--executable-file-name[=name]
-o
option is that --executable-file-name
considers the
--executable-path
, while -o
does not and accepts a
file name with directory. Furthermore, --executable-file-name
only applies to executables, not to other output formats selected.
-Ldir
-Idir
-llibrary
-O[n]
-O0
which is the default), the compiler's goal is to reduce the
compilation time and to make debugging produce the expected results.
Statements are independent: if you stop the program with a
breakpoint between statements, you can then assign a new value to
any variable or change the program counter to any other statement in
the same routine and get exactly the results you would expect from
the source code.
With optimization, the compiler tries to reduce code size and execution time. The higher the value of n, the more optimizations will be done, but the longer the compilation will take.
If you use multiple -O
options, with or without n, the
last such option is the one that is effective.
-g
gdb
. Unlike some
other compilers, GNU Pascal allows you to use -g
with
-O
. The shortcuts taken by optimized code may occasionally
produce surprising results: some variables you declared may not
exist at all; flow of control may briefly move where you did not
expect it; some statements may not be executed because they compute
constant results or their values were already at hand; some
statements may execute in different places because they were moved
out of loops. Nevertheless it proves possible to debug optimized
output. This makes it reasonable to use the optimizer for programs
still in the testing phase.
-s
-Wall
-Wall
, see the GCC warning options
(see Options to Request or Suppress Warnings),
while -Wall
only warns about such constructs that should be
easy to avoid in programs. Therefore, we suggest using -Wall
on most sources.
Note that some warnings (e.g., those about using uninitialized
variables) are never given unless you compile with optimization (see
above), because otherwise the compiler doesn't analyze the usage
patterns of variables.
-Werror
-S
.s
.
-c
.o
.
-static
-Dmacro[=def]
1
if def is omitted).
-b machine
-v
--classic-pascal-level-0
--classic-pascal
--extended-pascal
--object-pascal
--ucsd-pascal
--borland-pascal
--pascal-sc
--borland-pascal
) are suppressed.
By default, GNU Pascal allows the redefinition of some keywords. Each of these switches causes GNU Pascal to forbid the redefinition of keywords of the specified standard.
Valid ISO 7185 Pascal programs should compile properly with or
without --classic-pascal
. However, without this option,
certain GNU extensions and Pascal features from other dialects are
supported as well. With this option, they are rejected.
These options are not intended to be useful; they exist only to
satisfy pedants who would otherwise claim that GNU Pascal fails to
support the ISO Standard or is not really compatible to Borland
Pascal, or whatever. We recommend, rather, that users take advantage
of the extensions of GNU Pascal and disregard the limitations of
other compilers.
-pedantic-errors
-pedantic
option,
so you can, for instance, use -pedantic-errors
without
-pedantic
, but with --extended-pascal
.
--gpc-main=name
name
instead
of main
on the linker level. This is useful, e.g., when
working with some C libraries which define their own main
function and require the program's main entry point to be named
differently. (This option should preferably be used as a compiler
directive in the unit or module which links to that strange C
library, rather than be given on the command-line.)