Pascal Compilers

© 2009-2020 Kevan Hashemi, Brandeis Univiersity HEP Electronics Shop


Installing GPC
Compiling GPC
Stage ZeroStage OneStage TwoStage Three


Starting with LWDAQ 10, we compile our Pascal source code with the Free Pascal Compiler (FPC). For earlier versions, we used the GNU Pascal Compiler (GPC). We include below our notes on installing and compiling GPC.

Installing GPC

We installed GPC on MacOS, Windows, and Linux machines from 2003-2020. The GPC compiler is, in principle, a member of the GNU Compiler Collection (GCC). The back-end of the latest release of GPC is compatible with a patched version of GCC 3.4.6, but no later version. The GPC home page provides an introduction to GPC and the GPC Manual describes the compiler features in detail. But links to binary distributions on the home page are out of date. There are two ways to install GPC. One is to download the source code for the compiler, compile it yourself with GCC, and install the binaries you create. Another is to download pre-compiled binaries. The former is more arduous but at the same time more reliable. The latter is easier, but the resulting installation may be incompatible with your system, especially if you are working on Linux


Binary distributions of GPC for MacOS are available here (Microbizz, Maintained by Adriaan van Os). We use the most recent binary, built on MacOS 10.6, of which we provide this copy gpc346u4-10.6-Intel. The install places the GPC files in a folder /Developer/Pascal. The compiler is a 32-bit application that produces i386, 32-bit assembly code. By default GPC assembles to object code using the as command on the local system. When we install GCC Command Line Tools on MacOS 10.12, we get these assemblers:


The one in the i386 directory is the 32-bit GNU Assembler, and the one in the x86_64 is the 64-bit GNU Assembler. The other assembler is also GNU, but we are not sure of its target system. On MacOS 10.12+ the program invoked by as is a CLANG assembler, which is incompatible with the assembly code produced by the GPC compiler. When compiling with make, our solution is to have GPC produce assembler code, call the i386 assembler to create the object code, and link with gcc. When linking on MacOS 10.9 or later, we link to the 32-bit MacOS 10.8 SDK, which we provide as We place the MacOSX10.8.sdk folder in /Developer/SDKs. We direct gcc to link in a manner compatible with MacOS10.8 and later with:

-Wl,-syslibroot,/Developer/SDKs/MacOSX10.8.sdk/ -mmacosx-version-min=10.8 -m32

By this means, we produce static libraries, dynamic libraries, and stand-alone executables. To see the details of our build procedure, see Makefile. We are currently unable to produce an executable directly with GPC at the command line, despite having some luck a few years ago with a specs file.


Binary distributions of GPC for Cygwin on Windows are available here (GNU-GPC, Maintained by The African Chief). These are binaries and sources ready to install within the 32-bit Cygwin environment on Windows.

Binary distributions of GPC for MinGW on Windows are available here (GNU-GPC, Maintained by The African Chief). These are binaries and sources ready to install within the 32-bit MinGW environment on Windows.

We provide the following binary distributions for Windows.

gpc-20070904-windows-7-32bit: Compiled from 20070904 GPC sources on a 32-bit Windows 7 machine. Install within a 32-bit MinGW environment. This archive includes gcc 3.4.6.

To install any of these binary distributions, download the archive and place it in the top directory. Extract with the following command.

sudo tar -zxvf gpc-20070904-slc-6.5-32bit.tar.gz

The extraction will install the Pascal compiler in usr/local, using usr/local/bin for the commands, usr/local/lib for libraries. Test the compiler first by entering gpc at the command line.


There is no universal binary distribution for Linux. Here are some we have compiled.

gpc-20070904-slc-3.0-32bit: Compiled from 20070904 GPC sources on 32-bit, Scientific Linux 3.0 using GCC 3.4.6. This archive includes gcc 3.4.6.

gpc-20070904-slc-6.5-32bit: Compiled from 20070904 GPC sources on 32-bit Scientific Linux 6.5 using GCC 3.4.6. This archive includes gcc 3.4.6.

gpc-20070904-slc-6.5-64bit: Compiled from 20070904 GPC sources on 64-bit Scientific Linux 6.5 using GCC 3.4.6. This archive includes gcc 3.4.6. All libraries built with -fPIC so they can be linked to shared libraries.

To install, download the archive and place it in the top directory. Extract with a command like this:

sudo tar -zxvf archivename.tar.gz

The extraction will install the Pascal compiler in usr/local, using usr/local/bin for the commands, usr/local/lib for libraries. Test the compiler first by entering gpc at the command line. If the command does not exist, fix your default path:


When you run GPC, you should get a page of text describing your installation. You can now test the compiler on some Pascal source code. Your gpc may report that it cannot find certain libraries. If that's the case, our binary distribution is incompatible with your Linux system. You may be able to install GPC directly from your Linux version's home page, using yum, rpm, or up2date. Otherwise, you will have to compile GPC yourself.

Here are some Debian packages compiled by Peter Blackman. We have not tried them, but they may be more convenient to install than our own.

gpc-3.4_20070904-102t: Compiled from 20070904 GPC sources for 32-bit Debian machines.

gpc-3.4_20070904-102t: Compiled from 20070904 GPC sources for 64-bit Debian machines.

Please let us know if you have problems with any of the above distributions.

Compiling GPC

The GNU Pascal Compiler, GPC, is a program written in C. In theory, we could compile GPC with any C compiler, but in practice, we need a compiler compatible with the GPC back-end. Here we provide instructions for compiling GPC using GCC version 3.4.6. The entire process must, of course, be powered by a pre-existing C compiler, which we refer to as the local C compiler. So far as we know, any GCC C-compiler will do, but we may be wrong about that. Our first step in compiling GPC is to make sure we have a C-compiler installed on our machine.

cc --version

The above command should return the name and version of your local C compiler. We leave it to you to make sure that you have such a compiler installed. If the result is some GCC 3.x or 4.x compiler, you can be confident of success.

You will find generic instructions for compiling GPC source code here. We have not yet compiled GPC from sources on MacOS. But we have done so several times on Linux and Windows. In the following instructions, paragraphs that are specific to one platform begin with the name of the platform in bold. All other paragraphs apply to all platforms.

We build the GPC compiler in three stages. In Stage One, we invoke configure to generate a platform-specific makefile for Stage Two. In Stage Two, we use invoke make to compile the GCC_3.4.6 source code using the local C compiler, and to generate another makefile for Stage Three. In Stage Three, we invoke make to build a GCC_3.4.6 executable, compile the GPC sources with GCC_3.4.6, and install GPC in a directory of our choice. We start, however, with Stage Zero, which is preparing our system for the build.

Stage Zero

Windows: We install the developer version of MinGW, any distribution with version number 3.x, but not a 4.x version. We install the Msys shell program also, using the MSYS installer. MinGW provides a 32-bit Unix-like environment in which to compile GPC. We can install MinGW on 32-bit Windows machines or 64-bit Windows machines. In both cases, it will create a 32-bit version of GPC, which will in turn create 32-bit executables and libraries. A 64-bit native build of GPC would require adapting GCC 3.4.6 to MinGW-64.

The make command that compiles GCC_3.4.6 and GPC uses many utilites. We make sure that we have all of the following utilities installed.

  1. bash
  2. bzip2
  3. GNU sed
  4. GNU awk
  5. GNU m4
  6. bison
  7. flex
  8. autoconf
  9. texinfo
  10. help2man

Linux: We used yum on Scientific Linux 6.5 to install bison, flex, autoconf, textinfo and help2man. The default packages worked fine.

Windows: All but help2man are installed with the developer version of MinGW. We install this utility with:

mingw-get install msys-help2man

Download our GPC installation archive gpc-20070904-build.tar.gz. Unpack the archive with the following command:

tar -zxf gpc-20070904-build.tar.gz

Suppose you have unpacked the archive in directory /x. This directory now contains the following directories and files.

build {directory for building GPC}
gcc-3.4.6 {directory containing GCC_3.4.6 source code}
gcc-3.4.6/gcc/p {directory containing GPC_20070904 source code}
gcc-3.4.4.diff {patch to GCC required by GPC}
gcc-3.4.5-20060117-1.diff {patch to GCC required by Windows/MinGW}
gpc-20070904-dialect-bug.diff {patch to GPC fixes minor bugs}
gpc-20070904-mingw-bugfix.diff {patch to GPC required by Windows/MinGW}
os-hacks.h {a header file for Windows/MinGW}

Windows: Add the os-hacks.h header file to the MinGW include directory. In /x, copy the header file with:

cp os-hacks.h /mingw/include/os-hacks.h

Windows: We received extensive instruction on how to compile GPC in MinGW from Dave Bryan. Our instructions are based upon his.

Windows: Patch the GCC_3.4.6 source code for MinGW. In /x, apply with:

patch -p1 -t -d gcc-3.4.6 -i ../gcc-3.4.5-20060117-1.diff

Patch the GCC_3.4.6 source code for GPC. In /x, apply with:

patch -p1 -t -d gcc-3.4.6/gcc -i ../gcc-3.4.4.diff

Patch GPC source code to fix a couple of minor bugs. In /x, apply with:

patch -p0 -t -d gcc-3.4.6/gcc -i ../gpc-20070904-dialect-bug.diff

Windows: Patch the GPC source code for MinGW. In /x , apply with:

patch -p1 -t -d gcc-3.4.6 -i ../gpc-20070904-mingw-bugfix.diff

The source code is now ready to compile.

Stage One

Go to our build directory, and invoke the GCC_3.4.6 configure script. We pass the script two options. The --enable-languages option enables support for pascal. The --disable-multilib option makes sure we don't try to build 32-bit and 64-bit versions of the compiler at the same time. This is necessary on 64-bit machines, and does no harm on 32-bit machines. In /x/build invoke the script with:

/x/gcc-3.4.6/configure --enable-languages=pascal --disable-multilib

You should see a makefile in the /x/build directory when the configure is done.

Stage Two

The makefile in x/build will invoke the local C compiler to compile the GCC_3.4.6 source code. Depending upon the platform, we will have to pass different options and flags to the build.

Linux 32-bit: In x/build invoke make with:


If the build fails with the following error, your bison is incompatible with GCC_3.4.6.

gcc: c-parse.c: No such file or directory
gcc: no input files

We find that bison 2.4.1 works. You may be able to fix this error by applying this patch to gcc-3.4.6/gcc/ before you build, as described here.

Windows: For our compile to work in MinGW on Windows, we must tell the makefile where our system header files are and where our system libraries. On Windows7, we must specify that we want the local C compiler to use the MinGW standard string input-output routines, or else the %n format code, which is no longer supported in Window7, will generate gigabyte text files and cause the build to abort.


When we build a 64-bit Pascal compiler, we must make sure that the Pascal run-time library, libgpc.a, is position-independent so that we can link it into 64-bit shared libraries. The 32-bit Pascal compiler does not need to build position-independent objects because on 32-bit platforms we can include position-dependent code in shared libraries. On a 64-bit platform, however, we must build with the -fPIC option, which forces the local C-compiler and GCC_3.4.6 to generate position-independent code. Similarly, when we compile Pascal code on a 64-bit platform, you pass the -fPIC option to GPC so as to force it to produce position-independent objects, which we can link to our position-independent libgpc.a to produce a shared library.

Linux 64-bit: In x/build invoke make with:

make CFLAGS='-g -O2 -fPIC'

At the end of the build, we should have many object files in /x/build/gcc along with a newly-created makefile, which we will use in Stage Three.

Stage Three

The makefile in x/build/gcc will create a GCC_3.4.6 executable, use this to compile the GPC sources, and install the GPC executable and libraries. We install GPC in /usr/local with the following command. In /x/build/gcc enter:

sudo make pascal.install-with-gcc

We can make our own binary distribution of GPC, including GCC, with with the bindist-with-gcc process.

make pascal.bindist-with-gcc

You can set this binary distribution aside and give it to other users of the same platform. They will be able to extract it directly into their root file structure and run the compiler.

With the compiler installed, you can invoke it with gpc on the command line. See the GNU Pascal Manual

Windows 32-bit: So long as you stay in the c-drive, you will be able to invoke GPC and link to its run-time libraries without specifying any library paths. But if you move to another drive, GPC will be unable to find its run-time libraries in the /mingw/lib path, because GPC does not map this path to the MinGW library folder on the c-drive. Set the LIBRARY_PATH environment variable as below to point GPC to the correct folder.