Getting Started with FPC
by: Delax
Edits by: G.E. Ozz Nixon Jr.
Published: May 2004
©opyright 2009 by Friends of FPC
The Free Pascal Compiler sure is the best thing around since Borland stopped supporting
their Pascal compilers. FPC has support for various processor families, it is able to compile for multiple operating
systems, very Borland Pascal/Delphi compatible and best of all:
it's free!
One reason that FPC is not as popular as it's successor may be it's lack of an RAD IDE (Integrated Development Enviroment).
Newbies are scared of the "old fashioned" way of compiling a program or to use an "old looking" DOS Enviroment.
With this article I try to show complete newbies how to get started with FPC. We will first install the compiler and then
configure an external editor that will be used to write their program. By the way: the article is aimed at Windows programmers
or at least programmers that code on the windows platform.
Step 1: Downloading FPC
The first thing you should do is download the Free Pascal Compiler. You can get it at
http://www.freepascal.org/. At
the time of writing this article, the most current version is 1.0.10 (revision 2.2.4).
I suggest that you download the complete Win32 Installer image.
Step 2: Installing FPC
After the download is complete you should have an .EXE Installer file on your drive.
The default directory for 1.x was C:\PP, now is C:\FPC\$version\.

Windows Installer (Screen 1)

Select Full Installation (Screen 2)

Use the default (Screen 3)

I don't use Delphi - so I associate all files (Screen 4)

Review the path and settings (Screen 5)

Progress Meter (Screen 6)

The FPC "Changes" Report (Screen 7)

You can read the Read Me if you like (Screen 8)
(1.x) You will get a Windows Message at the end of the installation, telling you to set some
PATH variables in your AUTOEXEC.BAT. The line is:
SET PATH=C:\PP\BIN\GO32V2;C:\PP\BIN\WIN32
(2.x) You will not get a message about the variables as the installer automatically updated
"Control Panel -> System -> Advanced -> Environment Variables":

Notice the PATH settings
If your AUTOEXEC.BAT already has a PATH variable, just append the new paths like this:
SET PATH=C:\Windows;C:\PP\BIN\GO32V2;C:\PP\BIN\WIN32
Note (1.x): If you downloaded the Windows/DOS only compiler
the following entry may be enough: C:\PP\BIN
Now you are ready for action. Open a DOS box and test the compiler by starting the PPC386.EXE
in your FPC directory (default: "C:\PP\BIN\GO32V2" or "C:\FPC\$version\BIN\I386_WIN32").
Since you called the compiler without arguments it should present a list of parameters.
If you editing your AUTOEXEC.BAT and not System Environment variables and get a "file not found"
error, try rebooting your machine so the changes to your AUTOEXEC.BAT will take effect. If you
get this same message and you edited your System Environment variables, make sure you open a new
DOS window - if the error still happens - review the values you set for PATH.
Now we try to compile something. In your C:\<compiler folder>\SOURCE\DEMO directory is a file called
"HELLO.PP". In a DOS box, change the directory to C:\$lt;compiler folder$gt;\SOURCE\DEMO and call
"PPC386.EXE HELLO.PP".
C:> PPC386.EXE HELLO.PP
Free Pascal Compiler version (version id here)
Copyright (c) 1993-2004 by Florian Klaempfl
Target OS: DOS
Compiling hello.pp
Assembling hello
Linking hello.exe
21 lines compiled, 0.3 sec
C:> _
If everything went well, the compiler should have done his job. Now you should have a file
called "HELLO.EXE" in the same directory as "HELLO.PP".
Now you have tested the Free Pascal Compiler installed on your system. I will assume that it
is installed in C:\PP or C:\FPC. In this section I will show you how to configure an external Editor as your IDE.
Step 3: Downloading EditPlus
EditPlus is an "Internet Ready Text Editor", for coding HTML and various scripting languages. However,
it is able to work as an IDE for FPC as well. Other alternatives are UltraEdit, EditorOne, BBEdit, etc.
You can download EditPlus at
http://www.editplus.com/.
The editor is Shareware and you are allowed to use it for 30 days. After those 30 days it still works, but
you should really consider spending those $20.00USD. The most recent version by the time of writing this
article is 2.10c.
You need the editor as well as an extension for Pascal files. You can find this extension in "User Files".
It is called "Pascal.stx".
Step 4: Installing EditPlus
Just install EditPlus anywhere on your drive. Then, copy the "Pascal.stx" file in the same directory as EditPlus.
Now start EditPlus. Go into the Options Menu ("Tools/Preferences"). Then click on "Files/Settings & Syntax"
and "Add" on the right. A dialog "New Setting" will appear. Enter "Pascal" in the "Description" Field. The
"File Extension" is "Pas;pp;". Then click "Word Wrap" and enable it. It's your choice if you want to associate
Pascal Files in your Explorer.

We'll stick with the Preferences. Below the entries you just did is a field called "Syntax File". Click on the
dots to the right and search for the "Pascal.stx" file you (hopefully) downloaded.
So much for the "Files" entries. Now click on "Tools/User Tools". First enter a name for a new group (Group Name).
I suggest "Pascal" ;o). Then click on "Add Tool" and select "Program". A "New Program" dialog appears. Just call
the "Menu Text" "FPC Compiler". Then choose the dots to the right of "Command" and choose your
"C:\PP\BIN\GO32V2\PPC386.EXE" (DOS),
"C:\PP\BIN\WIN32\PPC386.EXE" (Windows) or
if you installed 2.x version you will simply enter
"C:\FPC\<version number here>\BIN\I386-WIN32\PPC386.EXE". select "File Path" as "Argument" and keep the "Initial Directory"
empty. Last but not least check "Capture Output" and "Promt for Arguments".

Yaaay! You're done! Now click on O.K. and restart EditPlus (necessary!).
To test your new IDE open some kind of FPC Demo File (MAGIC.PP or something). First you should notice that EditPlus
is highlighting Pascal Keywords. Don't worry if you don't like the color - you are able to choose ones for yourself ;o).
Anyway - Click "Tools" on the Menu Bar and choose the FPC Compiler. You will be asked for Arguments. Normally you
would enter some compiler switches (-TWin32, ...), but the Demos should not need any. If everything went well, you
should get an output window telling you that everything compiled without errors.
Additional Information
Again (as it can't be said enough) RTFM! Please read the manual. I know it is not THAT interesting, but if you encounter
problems it is the first place to look.
If you want to start programming in Pascal, I suggest you take a look at your local search engine or surf
our
Free Pascal Documents Library. Note that most tutorials in the web are
for Borland/Turbo Pascal. If so, try giving PPC386.EXE the Argument "-So" if you encounter problems compiling TP code.
Again something on Editors and IDEs etc. There ARE special IDEs for the Free Pascal Compiler.
(revised by G.E. Ozz Nixon Jr.) Lazarus is an open source RAD IDE project that over the 5 years since this article was originally written
by Dalex -- has became the standard GUI IDE for FPC.
Also, if you are a Linux or Mac OS X developer, the above steps are basically the same for other operating systems. The
main changes are the path (like /usr/bin, /usr/local/src/fpc/text/demo, etc.) and the binary file extension is not .EXE
and lastly on Mac OS X you do not have PPC386 you have ppcppc for the compiler. Plus, over the years there is a binary
front-end to the compiler called "fpc" (or DOS/WINDOWS "fpc.exe").