It is one of the most annoying points about GPC that there is no Integrated Development Environment like BP.EXE at the moment. We are working on it, but this will take some time, especially because GNU Pascal is a portable compiler intended to run under a large variety of operating systems in the same manner. Please be patient--or offer your help! (For the moment, you can try to use Borland's IDE for GNU Pascal--see below.)
The GNU Pascal Compiler, GPC, is called about like the command-line version of the Borland Pascal Compiler, BPC. Edit your source file(s) with your favorite ASCII editor (e.g. the Borland IDE), then call GNU Pascal with a command line like
C:\GNU-PAS> gpc hello.pas -o hello.exe
on your DOS or OS/2 box (with EMX you may omit the `-o ...') or
myhost/home/joe/gnu-pascal> gpc hello.pas -o hello
on your UNIX (or UNIX-compatible) system. Don't omit the suffix `.pas': GPC is a common interface for a Pascal compiler, a C, ObjC and C++ compiler, an assembler, a linker, and perhaps a Modula and FORTRAN compiler. From the extension of your source file GPC figures out which processor to run.
The -o
is a command line option which tells GPC how the
executable has to be named. This is not necessary for DOS and
OS/2, so we omit it in this file from now on.
Note that GPC is case-sensitive concerning file names, so it will not work if you type
C:\GNU-PAS> GPC HELLO.PAS -O HELLO.EXE
GPC is a very quiet compiler and doesn't print anything on the screen unless you request it or there is an error. If you want to see what is going on, invoke GPC with additional options:
-Q "don't be quiet" (or: Quassel-Modus in German)
(with capital `Q'!) means that GPC prints out the names of procedures and functions it processes, and
--verbose
means that GPC informs you about the stages of compilation, i.e. preprocessing, compiling, assembling, and linking.
One example (this time for OS/2):
[C:\GNU-Pascal] gpc --verbose -Q hello.pas
Throughout this chapter, we will tell you about a lot of command-line switches. They are all invoked this way.
After compilation, there will be an executable hello
file in
the current directory. (hello.exe
with DOS and OS/2.) Just
run it and enjoy. If there are errors, GNU Pascal will not stop
compilation after the first one--as Borland Pascal does--but
try to catch them all in one compilation. If you get more error
messages than your screen can hold, you can catch them in a file
(e.g. gpc.out
) in the following way:
gpc hello.pas 2>gpc.out
This works with OS/2 and any bash-like shell under UNIX; for DOS
you must get a replacement for command.com
which supports
this kind of redirection (see also the DJGPP FAQ).
You can also use Borland's IDE for GNU Pascal on the DOS platform: Install the GNU Pascal Compiler in the Tools menu (via Options/Tools).
Name: GNU Pascal Path: gpc Arguments: $SAVE ALL --verbose -Q $NAME($EDNAME).pas HotKey: Shift+F9
Note once more that GPC is case-sensitive, so it is important to
specify .pas
instead of the .PAS
Borland Pascal would
append otherwise!
You can include more command-line arguments to GNU Pascal (e.g. `--automake'; see below) as you will learn more about them.
Since Borland Pascal will try to recompile your program if you
use its run
menu function, you will need another "tool"
to run your program:
Name: run program Path: command.com Arguments: /c $NAME($EDNAME) HotKey: Shift+F10