The GNU Pascal Compiler (GPC) is a member of the GNU Compiler Collection. Its back-end is compatible with the GNU C Compiler (GCC) and all the other members of the collection.
GPC Home Introduction to GPC and the GPC Manual. The links to binary distributions are out of date, as are some of the links to the source code. There are instructions for compiling sources on Unix-like platforms, and we used these ourselves.
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).
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 Cygwin UNIX-like 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 Mingw UNIX-like environment on Windows.
There is no universal binary distribution for Linux. We have several here for you to download, but they may not work on your particular distribution.
GPC-20070904 and SLC 3.0.9: GPC version 20070904 compiled on a 32-bit, x686, Scientific Linux 3.0.9 machine. The file is named gpc-20070904-with-gcc.i686-pc-linux-gnu.tar.gz, indicating that it is the 20070904 version of GPC, compiled for an i686 processor running GNU-compatible Linux, and including necessary gcc libaries.
To install one of our Linux binaries, extract with the following command. You will be prompted for the root password because the files will be installed in the root file system.
sudo tar -zxvf gpc-20070904-with-gcc.i686-pc-linux-gnu.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.
Example: Download the latest LWDAQ zip archive from here, extract the LWDAQ directory, and cd to Build. Type make to build our lwdaq.so library.
On the other hand, your gpc may report that it cannot find certain libraries. If that's the case, then our binary distribution is incompatible with your Linux system. You may be able to install GPC directly from your Linux version's home page, or using yum, rpm, or up2date. Otherwise, you will have to compile GPC yourself.
You will find generic instructions for compiling GPC source code here (GNU-GPC, Maintained by Frank Heckenbach). We have not compiled GPC from sources on MacOS or Windows. But we have done so several times on Linux.
To compile for Linux, start by making sure that you have some version of the GCC compiler installed on your machine. You will need this compiler to compiler another, older version of GCC, and this older version will then be used to compile GPC. It does not matter what version of GCC you have installed on your machine right now, because it will be able to complile the source code of an older version of GCC. We will need the old version of GCC because its back-end is compatible with the GPC back-end.
Once you have a version of GCC installe, make sure you have the following utilities installed on our system.
To install help2man, you may or may not need the Perl module called "Locale::gettext". If you have problems installing help2manDownload gettext and extract. Change directory into the gettext directory and run the following commands to install the module.
perl Makefile.PL make make test make install
With gettext installed, you can configure help2man.
With these utilities installed, download the source code for GCC 3.4.6. You can use our gcc-core-3.4.6 archive. This C-compliler is compatible with the back-end of GPC. Later versions of GCC are not compatible, and cannot compile GPC. Configure and build the compiler.
[25-OCT-13] We are trying to compile GCC 3.4.6 on SLC 6.4 and failing. We can't seem to compile any version of GCC. We will figure this out and make a 64-bit GPC binary.
Download the GPC sources. You can use our GPC-20070904 archive. Follow the generic GPC compile instructions here. Configure and make the GPC libraries. When it comes to installing, we recommend that you install GPC with its own copy of GCC. Enter the gcc directory in your build area and type:
We made our own with-gcc binary distribution with:
You can set this binary distribution aside and give it to other users of the same Linux version. They will be able to extract it directly into their root file structure and run the compiler.
[28-OCT-13] When installing and uninstalling various versions of GCC on MacOS, the behavior of the default gcc command changes after re-starting the OS. The behavior after re-starting always makes more sense than before re-starting.
Today we set out to remove from our MacOS 10.7.5 MacBook Pro all traces of previous Xcode, GCC, and GPC installations. We begin by running the uninstaller provided by Xcode.
sudo /Developer/Library/uninstall-devtools -mode=all
We run uninstall-cltools, a script we found here, which removes the files installed by Xcode4's command line tool installer. With rm -fr we delete /Developer/Pascal, all as directories and files in /usr, and all gcc folders and files except the following, which are present on all MacOS 10.7 and 10.8 machines.
We re-start and confirm that we have no gcc (GNU c-compiler executable), no as (GNU assembler executable), and no gpc (GNU pascal compiler executable). We download an Xcode3.2 installer and run it, asking it to install support for MacOS 10.4 in addition to 10.5 and 10.6. We copy the SDKs directory files somewhere else, then run the uninstall-devtools and uninstall-cltools script. We download an Xcode4.6 installer and copy the Xcode4 application bundle to our Applications folder. We extract from the bundle the MacOS 10.7 and 10.8 SDKs and put them with our other SDKs. We put the Xcode4.6 application bundle in the trash and delete it. We run the Xcode4.6 command-line tools installer. We install GPC from gpc346u4-10.6-Intel, which we downloaded from Microbizz. We re-start our OS.
We have a Hell-World program, "program p; begin writeln('Hello World'); end." to test our GPC installation. We get two linker warnings, one saying we have not specified a minimum OS version and another saying we cannot build position-independent code from objects that are position-dependent. These go away when we specify a minimum OS version 10.4, 10.5, or 10.6 because these operating systems assume position-dependent code. For OS 10.7 and 10.8 we must specify position-dependence of the objects because the default for these versions is position-independence.
Kevan-Laptop:Build kevan$ gpc p.pas ld: warning: -macosx_version_min not specified, assuming 10.7 ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __start from /Developer/SDKs/MacOSX10.5.sdk//usr/lib/crt1.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie Kevan-Laptop:Build kevan$ gpc p.pas -Wl,-macosx_version_min,10.4 Kevan-Laptop:Build kevan$ gpc p.pas -Wl,-macosx_version_min,10.5 Kevan-Laptop:Build kevan$ gpc p.pas -Wl,-macosx_version_min,10.6 Kevan-Laptop:Build kevan$ gpc p.pas -Wl,-macosx_version_min,10.7 -Wl,-no_pie Kevan-Laptop:Build kevan$ gpc p.pas -Wl,-macosx_version_min,10.8 -Wl,-no_pie Kevan-Laptop:Build kevan$ ./a.out Hello World
We now attempt to link opbjects created by GPC, the GPC run-time library (in GPC installation), the MacOS SDK (in /Developer/SDKs), and a TclTk framework (in Frameworks) into a dynamic library (a.dylib).
Kevan-Laptop:Build kevan$ make gcc -dynamiclib -o a.dylib utils.o -FFrameworks -framework Tcl -framework Tk \ /Developer/Pascal/gpc346u4/lib/gcc/i386-apple-darwin10/3.4.6/libgpc.a \ -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk/ -mmacosx-version-min=10.4 ld: warning: ignoring file utils.o, file was built for i386 which is not the architecture being linked (x86_64):
The linker called by gcc is expecting to see 64-bit code on this 64-bit x686 machine. We must force it to link a 32-bit dynamic library with the "-m32" architecture option.
Kevan-Laptop:Build kevan$ make gcc -m32 -dynamiclib -o a.dylib utils.o -FFrameworks -framework Tcl -framework Tk \ /Developer/Pascal/gpc346u4/lib/gcc/i386-apple-darwin10/3.4.6/libgpc.a \ -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk/ -mmacosx-version-min=10.4
We attempt to cross-compile for PPC (power-pc) and OS 10.4, but the PPC assembler is not installed with the Xcode4 command-line tools. There is a way to transfer the PPC assembler from Xcode3 to Xcode4, but we are unable to get command-line cross-compiling to work with the gcc 4.2 linker. We abandon cross-compiling for PPC. We will compile PPC executables on our remaining PPC machines.