Go to the first, previous, next, last section, table of contents.


Command Line Options supported by GNU Pascal.

GPC is a command-line compiler, i.e., to compile a program you have to invoke `gpc' passing it the name of the file you want to compile, plus options.

GPC supports all command-line options that GCC knows. For a complete reference and descriptions of all options, see section `GCC Command Options' in the GCC Manual. Below, you will find a list of the additional options that GPC supports, and a list of GPC's most important options (including some of those supported by GCC as well).

You can mix options and file names on the command line. For the most part, the order doesn't matter. Order does matter, e.g., when you use several options of the same kind; for example, if you specify `-L' more than once, the directories are searched in the order specified. Note: Since many options have multiletter names; multiple single-letter options may not be grouped as is possible with many other programs: `-dr' is very different from `-d -r'.

Many options have long names starting with `--' or, completely equivalent `-f'. E.g., `--mixed-comments' is the same as `-fmixed-comments'. Some options tell GPC when to give warnings, i.e. diagnostic messages that report constructs which are not inherently erroneous but which are risky or suggest there may have been an error. Those options start with `-W'.

Most GPC specific options can also be changed during one compilation by using compiler directives in the source, e.g. `{$X+}' or `{$extended-syntax}' for `--extended-syntax' (see section Compiler Directives And The Preprocessor).

GPC understands the same environment variables GCC does (see section `Environment Variables Affecting GCC' in the GCC manual). In addition, GPC recognizes `GPC_EXEC_PREFIX' with the same meaning that `GCC_EXEC_PREFIX' has to GCC. GPC also recognizes `GCC_EXEC_PREFIX', but `GPC_EXEC_PREFIX' takes precedence.

GPC options besides those of GCC.

The following table lists the command line options GPC understands in addition to those understood by GCC.

--standard-pascal-level-0
Reject conformant arrays and anything besides ISO-7185 Standard Pascal.
--standard-pascal
Reject anything besides ISO-7185 Standard Pascal.
--extended-pascal
Reject anything besides ISO-10206 Extended Pascal.
--object-pascal
Reject anything besides (the implemented parts of) ANSI draft Object Pascal.
--borland-pascal
Try to emulate Borland Pascal, version 7.0.
--delphi
Try to emulate Borland Pascal, version 7.0, with some Delphi extensions.
--pascal-sc
Be strict about the implemented Pascal-SC extensions.
--gnu-pascal
Undo the effect of a previous `--foo-pascal', `--delphi' or `--pascal-sc' switch.
--lines
(Unimplemented switch for debugging).
--debug-tree
(Internal directive for debugging the compiler).
--debug-gpi
(Internal directive for debugging the compiler).
--debug-source
(Internal directive for debugging the compiler).
--progress-messages
Output source file names and line numbers while compiling.
--progress-bar
Output number of processed lines while compiling.
--autolink
Automatically link object files provided by units/modules or `{$L ...}' (default).
--no-autolink
Do not automatically link object files provided by units/modules/`{$L ...}'.
--automake
Automatically compile changed units/modules/`{$L ...}' files and link the object files provided.
--no-automake
Same as `--no-autolink'.
--autobuild
Automatically compile all units/modules/`{$L ...}' files and link the object files provided.
--no-autobuild
Same as `--no-autolink'.
--amtmpfile
(Internal switch used for AutoMake).
--extended-syntax
Enable certain `dangerous' features such as ignoring function results, pointer arithmetic or using `CString's as strings (same as `{$X+}').
--no-extended-syntax
Disable the dangerous features enabled by `--extended-syntax' (default; same as `{$X-}').
--signed-char
Let `Char' be a signed type.
--no-signed-char
Let `Char' be an unsigned type.
--unsigned-char
Let `Char' be an unsigned type.
--no-unsigned-char
Let `Char' be a signed type.
--short-circuit
Guarantee short-circuit Boolean evaluation (default; same as `{$B-}').
--no-short-circuit
Do not guarantee short-circuit Boolean evaluation (same as `{$B+}').
--mixed-comments
Allow comments like `{ ... *)' as required in ISO Pascal (default in Standard Pascal mode).
--no-mixed-comments
Ignore `{' and `}' within `(* ... *)' comments and vice versa (default).
--nested-comments
Allow nested comments like `{ { } }' and `(* (* *) *)'.
--no-nested-comments
Do not allow nested comments (default).
--delphi-comments
Allow Delphi style `//' comments (default).
--no-delphi-comments
Do not allow Delphi style `//' comments.
--macros
Expand macros (default).
--no-macros
Do not expand macros (default with `--borland-pascal' or `--delphi').
--ignore-function-results
Do not complain when a function is called like a procedure.
--no-ignore-function-results
Complain when a function is called like a procedure (default).
--borland-char-constants
Allow for Borland-style character constants like `#27' or `^L' (default).
--no-borland-char-constants
Reject Borland-style character constants like `#27' or `^L' (default in Standard Pascal mode).
--truncate-strings
Truncate strings being assigned to other strings of too short capacity..
--no-truncate-strings
Treat string assignments to other strings of too short capacity as errors..
--exact-compare-strings
Do not blank-pad strings for comparisons.
--no-exact-compare-strings
Blank-pad strings for comparisons.
--io-checking
Do automatic run-time checks after I/O operations (same as `{$I+}').
--no-io-checking
Do not check I/O operations automatically (same as `{$I-}').
--write-clip-strings
In write statements, truncate strings exceeding their field width (`Write (SomeLongString : 3)').
--no-write-clip-strings
Do not truncate strings exceeding their field width.
--write-real-blank
Output a blank in front of positive reals in exponential form (default).
--no-write-real-blank
Do not output a blank in front of positive reals in exponential form.
--write-capital-exponent
Write real exponents with a capital `E'.
--no-write-capital-exponent
Write real exponents with a lowercase `e'.
--transparent-file-names
Derive external file names from variable names.
--no-transparent-file-names
Do not derive external file names from variable names (default).
--field-widths
Comma-separated list of default field widths for Integer, Real, Boolean, LongInt, LongReal.
--no-field-widths
Reset the default field widths.
--pedantic
Warn about everything rejected in some dialect, e.g. redefinition of its keywords.
--no-pedantic
Don't give pedantic warnings.
--stack-checking
Enable stack checking (same as `{$S+}').
--no-stack-checking
Disable stack checking (same as `{$S-}').
--typed-address
Make the result of the address operator typed (same as `{$T+}', default).
--no-typed-address
Make the result of the address operator an untyped pointer (same as `{$T-}').
--setlimit
Define the range for `set of Integer' etc..
--gpc-main
External name for the program's entry point (default: `main').
--interface-only
Compile only the interface part of a unit/module and exit.
--implementation-only
Do not produce a GPI file; only compile the implementation part.
--executable-file-name
Name for the output file, if specified; otherwise derive from main source file name.
--unit-path
Directories where to look for unit/module sources.
--no-unit-path
Forget about directories where to look for unit/module sources.
--object-path
Directories where to look for additional object (and source) files.
--no-object-path
Forget about directories where to look for additional object (and source) files.
--executable-path
Path where to create the executable file.
--no-executable-path
Create the executable file in the directory where the main source is (default).
--unit-destination-path
Path where to create object and GPI files.
--no-unit-destination-path
Create object and GPI files in the current directory (default).
--object-destination-path
Path where to create additional object files.
--no-object-destination-path
Create additional object files in the current directory (default).
--no-default-paths
Do not add a default path to the unit and object path.
--gpi-destination-path
(Internal switch used for AutoMake).
--uses
Add an implicit `uses' clause.
--cidefine
Define a case-insensitive macro.
--csdefine
Define a case-sensitive macro.
-Wwarnings
Enable warnings (same as `{$W+}').
-Wno-warnings
Disable warnings (same as `{$W-}').
-Wfield-name-problem
Warn about ignored field names in initializers (default).
-Wno-field-name-problem
Do not warn about ignored field names in initializers.
-Wobject-directives
Warn about unimplemented `private', `protected' and `public' directives (default).
-Wno-object-directives
Do not warn about unimplemented `private', `protected' and `public' directives.
-Wtyped-const
Warn about misuse of typed constants as initialized variables (default).
-Wno-typed-const
Do not warn about misuse of typed constants as initialized variables.
-Wnear-far
Warn about use of useless `near' or `far' directives (default).
-Wno-near-far
Do not warn about use of useless `near' or `far' directives.
-Wunderscore
Warn about double/leading/trailing underscores in identifiers.
-Wno-underscore
Do not warn about double/leading/trailing underscores in identifiers.
-Wmixed-comments
Warn about mixed comments like `{ ... *)'.
-Wno-mixed-comments
Do not warn about mixed comments.
-Wnested-comments
Warn about nested comments like `{ { } }'.
-Wno-nested-comments
Do not warn about nested comments.

The most commonly used options to 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 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
Check whether modules/units used must be recompiled and do the recompilation when necessary.
--unit-path=dir[:dir...]
Search the given directories for units and object files.
--object-path=dir[:dir...]
Search the given directories for object files.
--unit-destination-path=dir
Place units compiled into the directory dir. The default is the current directory.
--object-destination-path=dir
Place object files compiled into the directory dir. The default is the directory given with `--unit-destination-path'.
--executable-path=dir
Place the executable compiled into the directory dir. The default is the main source file's directory.
-o file
Place output in file file. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file, etc. 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]
Derive the executable file name from the source file name, or use name as the executable file name. The difference to the `-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
Search the directory dir for libraries. Can be given multiple times.
-Idir
Search the directory dir for include files. Can be given multiple times.
-llibrary
Search the library named library when linking. This option must be placed on the command line after all source or object files or other libraries that reference the library.
-O[n]
Select the optimization level. Without optimization (or `-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
Produce debugging information suitable for `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
Remove all symbol table and relocation information from the executable. Note: this has no influence on the performance of the compiled executable.
-Wall
Give warnings for a number of constructs which are not inherently erroneous but which are risky or suggest there may have been an error. There are additional warning options not implied by `-Wall', see the GCC warning options (see section `Options to Request or Suppress Warnings' in the GCC manual), while `-Wall' only warns about such constructs that should be easy to avoid in programs. Therefore, we suggest using `-Wall' on most sources.
-Werror
Turn all warnings into errors.
-S
Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each source file. By default, the assembler file name for a source file is made by replacing the extension with `.s'.
-c
Compile and assemble the source files, but do not link. The output is in the form of an object file for each source file. By default, the object file name for a source file is made by replacing the extension with `.o'.
-static
On systems that support dynamic linking, this prevents linking with the shared libraries, i.e. forces static linking. On other systems, this option has no effect.
-Dmacro[=defn]
Define the macro and conditional macro as defn (or as `1' if defn is omitted).
-b machine
The argument machine specifies the target machine for compilation. This is useful when you have installed GNU Pascal as a cross-compiler.
-v
Print (on standard error) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper.
--standard-pascal-level-0
--standard-pascal
--extended-pascal
--object-pascal
--borland-pascal
--pascal-sc
GNU Pascal supports the features of several different Pascal standards and dialects. By default, they are all enabled. These switches tell GPC to restrict itself to the features of the specified standard. It does not enable any additional features. Warnings about constructs which would be legal in the specified dialect (e.g. assignment to a typed constant with `--borland-pascal') are suppressed. By default, GNU Pascal allows redefinition of keywords. Each of these switches causes GNU Pascal to forbid the redefinition of keywords of the specified standard. Valid ISO Standard Pascal programs should compile properly with or without `--standard-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
Produce errors rather than warnings for portability violations. Unlike in C, this does not imply the `-pedantic' option, so you can, for instance, use `-pedantic-errors' without `-pedantic', but with `--extended-pascal'.
--gpc-main=name
Name the entry point of the main program `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.


Go to the first, previous, next, last section, table of contents.