I'm writing this guide because I noticed people seem to experience the same
problems I had with FPC and Lazarus and same questions are asked all over.
This guide is for anyone inexperienced in getting FPC and Lazarus to work properly.
FPC: (read only if you DON'T want to use Lazarus, otherwise skip to next)

There are 2 ways to get FPC.
1st is to get the "all-in-one" package of precompiled fpc from
2nd is to use SVN as described on www.freepascal.org page.
NOTE: if you want to use precompiled Lazarus, don't get FPC as separate package.
You need a binary of FPC 2.0.x if you wish to compile SVN fpc.
You can get them here.

After installing FPC ether way there is one more thing you need to check.
There's a file fpc.cfg which you must edit and make sure these lines point to the right paths:

NOTE: $fpcversion is always eqal to the version number of the FPC binary which is currently in use. $fpctarget specifies the OS(don't edit them)

If you get an error like "unit SysUtils not found" it's because your FPC paths are not set correctly.
In windows you also need to specify PATH to your FPC executable so you can use it in command line.
There's a "setpath.bat" file in pp\bin\$fpctarget\ which will do this for you.
To test if FPC works correctly try to compile a simple hello world program which uses some FCL unit like for example "xmlcfg";(just add it to uses section)
If the path is right everything should compile OK.


As with FPC there are 2 ways to get Lazarus.

1st: Get it from www.lazarus.freepascal.org as a binary package.
NOTE: for linux users you need:
You DON'T need the .src.rpm packages. The XXX must be same for all 3 packages. Install fpc and fpcsrc rpm's 1st.
Windows users must only get the setup executable and install it.

2nd: SVN. If you want to use Lazarus from SVN you need to have working FPC installed. See sections above. To get Lazarus from SVN go the Lazarus homepage and see the instructions.

After you run lazarus for the first time it may ask you about FPC paths.
Apart from FPC source path, all others are REQUIRED.
You need to specify where Lazarus itself is, where FPC fpc[.exe] is
and if you have FPC sources it's good to specify those too(so you can browse them with CTRL+CLICK)
Path to "make" is not required, unless you are on FreeBSD where you should use path to gmake!

Getting GDB to work.

For windows: get mingw package with GDB(snapshot version 6.3). Install it somewhere.
Go to enviroment options/debugger choose gdb(without SSH) and set the path to the gdb executable.
In windows it's probably C:\mingw\bin\gdb.exe
In linux it's probably /usr/bin/gdb
NOTE: You CAN'T run programs with GDB if you strip GDB info or use run-parameter application.
Also make sure you have Generate Debugging Info For GDB checked in if you want to use GDB.
Smartlinking must be also OFF and I'd advise agains optimalizations too.

Reducing filesize with Lazarus:
All OSes: To reduce the filesize go to
Project/Compiler Options/Linking
Uncheck all except Strip Symbols From Executable (-Xs)
and Check Link Smart(-XX)

This should produce filesizes ~1Mb(I think there's a strip bug in win32 in older Lazarus versions, you need to strip it manualy)
If you get bigger than 2Mb in windows start the command line and go to your project. If you have FPC in path just type "strip filename.exe"

Your link tab should look like this:
Config Options

To reduce filesize even more you can use UPX.
UPX is provided with FPC in windows. You will need to get it in Linux yourself.
If you have FPC in PATH "upx filename.exe"(same for linux if you got UPX)
You should get filesize about 500kb.

SPECIAL NOTE: UPX brakes program parameters(paramstr) in Linux because it first uncompresses it to /tmp. If you use paramstr(0) for something don't use UPX.

I hope this guide will provide useful and perhaps make some of you with negative experiences with FPC reconsider. If you find any errors/mistakes or suggestions send me a mail.


Use of libraries and external code:

I've noticed that many people have problems compiling applications which
use some sort of "external" code. Most notably people download some
contributed units/package and can't set the paths right. He's an example
on how to set up JEDI-SDL.

Download and unpack jedi-sdl somewhere. Copy the directory SDL
to your projects directory (example: /home/user/MyProject/SDL)
Now to be able to compile your application which uses SDL you need
to add: -FuSDL and -FiSDL when compiling like so:
"fpc -FuSDL -FiSDL MyProgram.pas"
If you use Lazarus, you can do this when you fill in the
Project/Compiler Options/Other Units and Includes
You'll need to do this for every project which uses some external
NOTE: a .ppu file is "pascal plus unit" it's a compiled FPC unit.
You can use ppu files without their sources but you won't be able
to use things like code-completion if you don't have their sources.