Compiling the Latest Lazarus/Free Pascal for Raspberry Pi

(updated Sep 2017 to discuss latest seed/bootstrap compiler)

I have long wanted a recent version of Lazarus for Raspberry Pi. I’ve looked at recompiling it, but the exact instructions have been hard to come by. Until last week! I accidently stumbled into Tweaking4All’s blog showing exactly how to do it:

Install Lazarus Pascal RPI 2

His instructions start from a brand new RPI Model 2 with a blank SD card and get you to a running installation. I’ve followed the procedure 3 times now and it has worked w/o problem.

Before going any further, I should mention this to any Lazarus / Free Pascal newcomer: if you have never used Lazarus before and just want to play with it, don’t follow these procedures. They are long and complicated. Instead, just install the old version of the compiler using these instructions. The old version of the compiler is very stable and most likely has all the features a newcomer will want.

If you want to seriously write Pascal code for the RPI, THEN these instructions are worth the extra trouble!

I’m going to summarize the steps as I did them. I also start with the assumption you already have a running RPI. I am using a Model 2 B with a USB HDD (you won’t need one, but it make everything run snappier).

My instructions have been modified to produce a compiler that will produce ARMV6 code which will allow your programs to run on both Model 1 and 2. If you are going to only use your code on model 2’s, change the OPT on all of the make commands to remove the -CpARMV6  and -OpARMV6 switches.

These are terse instructions and assume you know what you are doing. If you’ve not done this before, I suggest you use the original site. Once you are familar with the procedure, these instructions are easy to copy/paste straight into a terminal window.

Prepare the RPI

It is best to use SSH, not VNC to access the RPI as you want to reduce memory /CPU consumption as much as possible. For the same reason, make sure Firefox is NOT running.

I make sure the O/S is up to date and the Raspbian supplied version of Lazarus / Free Pascal has been removed.

sudo su
apt-get update
apt-get upgrade
apt-get remove lazarus
apt-get remove fpc
apt-get autoremove

sudo su

Everything I do from this point forward (until I mention othersize) is done as root. Therefore, rather than constantly have to remember to type sudo, I will simply type

sudo su

to become root.

Increase Swap File Size

The default swap file size is 256MB. It appears that trying to recompile the Free Pascal compiler will not work unless you increase the swapsize to 1GB. Once you have built the compiler, you can go back to a swap file of 256MB.

Make sure that you have enough disk space to do this:

rpi/~:df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           97G  6.1G   87G   7% /
/dev/root        97G  6.1G   87G   7% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  248K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  34% /boot

On my RPI, you can see that root has 87G available. I have plenty of room to increase the swap file size AND recompile the compiler.

Edit the config file

vi /etc/dphys-swapfile

and it will contain only the line:


remember that value, and set it to:


Save the config file and restart swapping:

/etc/init.d/dphys-swapfile stop
/etc/init.d/dphys-swapfile start

ls /var and verify /var/swap is now 1GB:

rpi/~:ls -lh /var
total 1001M
drwxr-xr-x  2 root root  4.0K Jun 13 18:02 agentx/
drwxr-xr-x  2 root root  4.0K Jun 13 06:25 backups/
drwxr-xr-x 12 root root  4.0K Jan 21  2014 cache/
drwxr-xr-x 43 root root  4.0K Apr 27 14:47 lib/
drwxrwsr-x  2 root uucp  4.0K Dec 25  2012 local/
lrwxrwxrwx  1 root root     9 Feb  8  2013 lock -> /run/lock/
drwxr-xr-x 11 root root  4.0K Jun 13 18:02 log/
drwxrwsr-x  2 root mail  4.0K Feb  8  2013 mail/
drwxr-xr-x  2 root root  4.0K Feb  8  2013 opt/
lrwxrwxrwx  1 root root     4 Feb  8  2013 run -> /run/
drwxr-xr-x  4 root root  4.0K Feb  8  2013 spool/
-rw-------  1 root root 1000M Jun 12 11:17 swap
drwxrwxrwt  2 root root  4.0K May 21 08:55 tmp/
drwxrwxr-x  2 root danh  4.0K Jan 21  2014 www/

Install subversion

apt-get install -y subversion

Install the Seed/Bootstrap Pascal Compiler

Sep 2017 Note: The bootstrap compiler is found at HOWEVER, not every version has been including the linux-arm release. For example, at time of writing, it exists for 2.6.3 and 3.0.2, but not 3.0.0.

This can limit the versions of FPC you can compile. From what I can tell, you need the prior version to compile the version in question. In other words, if you want to compile 3.0.2, you need 3.0.0 BUT it isn’t available.

As of Mar 2017, the bootstrap compiler is located here:

You will want the fpc-3.0.2.arm-linux-eabihf-raspberry.tar compiler.

Copy the compiler onto your system:

mkdir /usr/local/fpc
cd /usr/local/fpc
tar xvf fpc-3.0.2.arm-linux-eabihf-raspberry.tar
cd fpc-3.0.2.arm-linux

You are ready to install the compiler. You MUST ANSWER /usr/local to the first question! To all other questions, just press enter to accept the default.

./                #ANSWER 1st Q with /usr/local!!!! Rest are default.

Install Latest Version of Free Pascal

These instructions are going to install the most recent version of Free Pascal which is found at That probably isn’t the best idea. The trunk version is test code and can contain bugs. This bit me hard when following the instructions for an Orange Pi – the compile failed and I wasted hours blaming it on the OPI only to find it was issues with the source. I fell back to the most recent release (3.0.4) and that worked just fine.

If you want to install an older version, take a look at to decide the version.

If you decide to use an older version you will alter the svn command from what I have below (again, note, I am using the ARMV6 options to force the compile to generate V6 compatible code for my old RPIs):

cd /usr/local/fpc
svn co source 
cd source
# each of the following are fairly slow and may abort with errors
# I copy and paste them one at a time:
make all OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6"
make install OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6" PREFIX=/usr/local
make install sourceinstall OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6" PREFIX=/usr/local

Now you need to determine the installed version of FPC and create a sym link to that version.

To see the versions of pascal installed, type:

rpi/~:ls /usr/local/lib/fpc
2.6.4/  3.0.1/  lexyacc/

I’m going to be using 3.0.1. The 2.6.4 version is the seed compiler. I suspect it would not be a good idea to use it as your production compiler.

Remove the old sym link and create a new one to the 3.1.1 compiler:

rm -f /usr/local/bin/ppcarm
ln -sf /usr/local/lib/fpc/3.0.1/ppcarm /usr/local/bin/ppcarm

Finally, verify that when you invoke the fpc compiler, you get the version you expect:

fpc -iW

Install Additional Packages

apt-get install libx11-dev libgdk-pixbuf2.0-dev libcairo2-dev gir1.2-coglpango-1.0 libpangox-1.0-dev xorg-dev libgtk2.0-dev libpango1.0-dev

Download and Compile Lazarus

As with FPC, this will download the latest version. You can find old versions at If you choose to use one, update the svn command below.

mkdir /usr/local/lazarus
cd /usr/local/lazarus
svn co source
cd source
#copy/paste the following one at a time to verify they 
#both work without error
make all OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6"
make install OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6" PREFIX=/usr/local

Remove Lazarus Source

rm -rf /usr/local/lazarus

You can also remove the compiler source:

rm -rf /usr/local/fpc/source

Fixing the GCC Library path

As set up so far, the compiler will run, but linking will return a warning indicating crtbegin.o and crtend.o could not be found. The program still links OK, but I don’t like warnings like this.

To correct the problem, I located crtbegin.o using

sudo find / -name crtbegin.o

It is in /usr/lib/gcc/arm-linux-gnueabihf/4.6.

This library needs to be added to the /etc/fpc.cfg file.

sudo vi /etc/fpc.cfg

If you look thru this file you will find a comment for the library, but no path:

# path to the gcclib

You just need to add the path found above:

# path to the gcclib

Ready to Run Lazarus

You are ready to run Lazarus. First, exit so you are no longer root. Use whoami to verify you are back on your normal user (pi maybe?).

I’m assuming if you are trying to do all of this yourself, you understand Lazarus runs in XWindows and you will need to be running XWindows either directly via the HDMI connection or by using tightVNC to access the RPI. If none of this makes sense, see the source article. It will explain this much better.

To start lazarus, click on <menu> | Programming | Lazarus.

If you had Lazarus installed already, you will most likely see this Upgrade Window. Just click Upgrade:


Chances are pretty good that you will get the ‘Configure Lazarus IDE’ window next:


I use the following settings for each tab. If the setting is correct, you should see ‘OK’ in the 2nd window.

Lazarus Tab: /usr/local/share/lazarus/

Compiler Tab: fpc

FPC Sources Tab: /usr/local/share/src/fpc-x.x.x/fpc

Make Tab: make

Debugger Tab: /usr/bin/gdb

Click on Start IDE.

I like to do a simple Hello World test:


Lastly, if you changed the swap file size, go back and set it back to the original size and reboot the RPI.

This entry was posted in c-lazarus, c-rpi and tagged . Bookmark the permalink.

8 Responses to Compiling the Latest Lazarus/Free Pascal for Raspberry Pi

  1. Pingback: Using Lazarus and the Adafruit PiTFT Display + TouchScreen for RaspBerry Pi | Big Dan the Blogging Man

  2. Pingback: Building Free Pascal / Lazarus Cross Compiler for Raspberry Pi | Big Dan the Blogging Man

  3. Ahmad says:

    Thanks Big dan
    I have RPI1B+ and PFC2.6.4, Lazarus1.2.4 on it.
    Can i use this PFC2.6.4 as seed compiler for compiling trunk version 3.1.1?

    • Dan TheMan says:

      I’m going to say probably, but I can only say for a fact that the procedure I outlined works. The procedure uses FPC 2.6.4, but it uses a version the compiler located on sourceforge. This procedure is complex enough, chances are something is going to need to be tweaked to get it to work for you.

      I would just install the seed compiler from source forge and delete it after you are done. Then you don’t have to try to figure out why something fails, if it does.

      Check out the tweaking4all link at the very top of my post. There are quite a few people playing with the latest/greatest stuff there and they can provide more help.

  4. Brian LONNON says:

    I have followed the instructions for setting the gcc library path in fpc.cfg. However, when I run lazarus, it says system.ppu can’t be found on the compiler tab. I have no idea what to do! If I rem out the path to gcc I entered, then the compiler works, but of course there are stil the crt warning messages

  5. Pingback: Compiling Free Pascal / Lazarus on Orange Pi | Big Dan the Blogging Man

  6. Pingback: fpc, Lazarus 설치 -

  7. Leo says:

    make all OPT = “- dFPC_ARMHF -CpARMV6 -OpARMV6”

    make: -iVSPTPSOTO: Command not found
    Makefile:3099: *** The only supported starting compiler version is 3.2.0. You are trying to build with .. Stop.

    How to solve this error?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.