Freepascal and Lazarus on Raspberry Pi

A page describing how to get the latest Freepascal and Lazarus development systems on all versions of the Raspberry Pi and Raspbian wheezy and jessie in optimal format, targeted at ARMV6 and ARMV7.

Pascal has been a comfortable programming language since I started programming in the 70ties. Coming from the Portable P2 and P4 compilers on Digital computers, made by the team of Niklaus Wirth, HP1000 Pascal, VAX/VMS Pascal via Turbo Pascal on MS-DOS and Delphi on Windows to Freepascal and Lazarus on the Raspberry. Now getting freepascal and Lazarus on the Pi is easy but you get quite old versions:

sudo su
apt-get install fp-compiler
apt-get install lazarus

On Raspbian wheezy you get Freepascal 2.6.0 and Lazarus 0.9.30.4. version dating from 2012. Working but not quite bleeding edge. Perfect for a first session! On Raspbian jessie you get more recent versions: Freepascal 2.6.4 and Lazarus 1.2.4. Much better! Note that for me Lazarus did not show up in the Programming menu on the desktop on jessie, but easy to add yourself with the menu editor (lazarus is located somewhere in /usr/local/). Freepascal is missing the character based fp IDE alas. And the programs compiled on the Raspberry Pi 2 B crashed on the older Raspberry Pi for me. So far so good for most of us. But not what I wanted. I have both Raspberry Pi’s Version 1 and the newer Version 2 systems. All systems run Lazarus on the desktop, but the older version 1 systems are running Lazarus quite slow due to the ARM V6 CPU and lack of memory. But the resulting programs are running fast enough, we have a real compiler here! What I want is:

compile and test on the Raspberry Pi 2 MB and enjoy the speed.
Run on all Raspberry Pi models, so limited to ARMV6.
Run on older wheezy and modern jessie Raspbian.
The RPi 2 has four ARM V7 cores, Freepascal and Lazarus will benefit in speed from this architecture if compiled for ARMV7.
So I set out to build images of Raspbian with more current versions of Freepascal and Lazarus on both latest Raspbian jessie and wheezy

Recipe for ARM V6 RPi versions 1 and 2 Model A, A+, B, B+, 2B
Recipe ARM V7 version 2 Model B
Building the latest version of Feepascal requires a seed compiler, version 2.6.4. This is available as binary for ARM, a generic version. The trick in building Lazarus is making sure the Freepascal compiler is targeted for the same architecture, so we have to build a Freepascal compiler for the same architecture,.

Setup a fresh system

First a fresh system, get the latest jessie and/or wheezy from raspberrypi.org. These are the steps I perform for a new system. My main system is a Windows system, I do most work from there, including remote access.

Image SD card (Win32DiskImager), 16GB minimal. 8 GB may work, but I often get problems with installing Lazarus due to out of disk space.

Boot and login (user pi, password raspberry) locally

With raspi-config at least change

Expand file system
Boot into commandline (desktop is in the way during the build!)
Change password – Overclock (medium for older, RPI2 voor RPi2 B)
Advanced options:
enable ssh
memory split to 16 MB, you can chage that back later for graphics work – change hostname and reboot
Get the IP address assigned to the Pi Type

 ifconfig 

and note the IP address assigned to the RPi. Now you can use PuTTY from Windows to access the command line of your Pi or continue on the RPi itself.

Get rights as root for the whole session

sudo su

Increase swapfile to prevent ‘out of memory’ during compilation

nano /etc/dphys-swapfile
/etc/init.d/dphys-swapfile stop
/etc/init.d/dphys-swapfile start
ls -lh /var

change from 100 to 1000 and check its 1000M now. Remember to cut that back to the default after the builds!

Get a current system

apt-get update
apt-get upgrade

Make some room,

Software I do not intend to use at all and take up a lot of disk space

apt-get -y purge wolfram-engine scratch minecraft-pi sonic-pi dillo gpicview penguinspuzzle
apt-get remove --purge oracle-java8-jdk openjdk-7-jre oracle-java7-jdk openjdk-8-jre
apt-get purge libreoffice*
sudo apt-get clean
sudo apt-get autoremove
apt-get remove fp-compiler
apt-het remove lazarus
apt-get -y autoremove 
apt-get -y clean 
df -h 

Get subversion and unzip

apt-get update
apt-get install subversion unzip

Get seed compiler fpc 2.6.4 installed

 
mkdir /usr/local/fpc 
cd /usr/local/fpc 
wget -O fpc-2.6.4.arm-linux.tar http://sourceforge.net/projects/freepascal/files/Linux/2.6.4/fpc-2.6.4.arm-linux.tar/download 
tar xvf fpc-2.6.4.arm-linux.tar 
cd fpc-2.6.4.arm-linux 
./install.sh 

answer location question from script with /usr/local, other questions with Y

ls /usr/local/lib/fpc y

to check it has 2.6.4

Cleanup

 
rm /usr/local/fpc/fpc-2.6.4.arm-linux.tar 

After installing FPC, type fp and use the IDE to enter and compile the first program:

program test ;

begin
  writeln('Hello world!');
end.

Save,as helloworld, build and run it with

./helloworld

Hello world!

screenshotARMv7

Raspberry Pi 2 Model B only! Resulting programs only run on RPi 2B!

Install fpc trunk (version 3.1.1 at the moment)

cd /usr/local/fpc
svn co http://svn.freepascal.org/svn/fpc/trunk source
cd source
make all OPT=-dFPC_ARMHF
make install OPT=-dFPC_ARMHF PREFIX=/usr/local
make install sourceinstall OPT=-dFPC_ARMHF PREFIX=/usr/local
ls /usr/local/lib/fpc

shows 2.6.4 and 3.1.1 present.

Now make fpc 3.1.1 available

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

Install some packages

apt-get update
apt-get install -y 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

Get the source

This time I show to get not the bleeding edge trunk Lazarus 1.5, but the fix 1.4.5 version.

mkdir /usr/local/lazarus
cd /usr/local/lazarus
svn co http://svn.freepascal.org/svn/lazarus/branches/fixes_1_4 source

cd source
make all OPT=-dFPC_ARMHF
make install OPT=-dFPC_ARMHF PREFIX=/usr/local

Now continue with the Post build steps!

ARMv6

Resulting programs run on all RPi’s! Install fpc trunk (version 3.1.1 at the moment)

cd /usr/local/fpc
svn co http://svn.freepascal.org/svn/fpc/trunk source
cd source
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
ls /usr/local/lib/fpc

shows 2.6.4 and 3.1.1 present Now make fpc 3.1.1 available

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

Install some packages

apt-get update
apt-get install -y 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

Get the source

mkdir /usr/local/lazarus
cd /usr/local/lazarus
svn co http://svn.freepascal.org/svn/lazarus/trunk source
cd source 
make all OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6"
make install OPT="-dFPC_ARMHF -CpARMV6 -OpARMV6" PREFIX=/usr/local

Post build steps

Cleanup the source code

rm -rf /usr/local/lazarus

Set swapfile to default

nano /etc/dphys-swapfile
/etc/init.d/dphys-swapfile stop
/etc/init.d/dphys-swapfile start
ls -lh /var

change from 1000 to 100 and check its 100M now.

Fixing the GCC Library path

nano /etc/fpc.cfg

Change the line

# path to the gcclib

to

# path to the gcclib
-Fl/usr/lib/gcc/arm-linux-gnueabihf/4.6

Start Lazarus

You can start Lazarus from the desktop

startx

With jessie the Lazarus entry did not appear in the menu programming. Add this yourself with the Menu editor, browse the computer to find the lazarus executable in /usr/local/share/lazarus, the desktop icon is there also. Lazarus asks the first time run where the fpc sources are

/usr/local/fpc/source

Now you are ready to run! Resources from which I learned how to write the steps above! Thank you!

How to install Lazarus Pascal on Raspberry Pi 2 (Raspbian), Tweaking4All
Compiling the Latest Lazarus/Free Pascal for Raspberry Pi, Big Dan the Blogging Man
Raspberry Pi 2, FreePascal, Lazarus and Delphi, Simon J Stuart
http://forum.lazarus.freepascal.org/index.php?topic=30647.0

Home

News

UCSD p_system updated

The UCSD p-System part of the site has been enhanced with all I had in my archive. This descendent of ...

Read More

Pascal-M V1.4

Pascal V1.4, the latest Pascal-M compiler/interpreter. Many improvements since V1.0, mostly the VAX/VMS - Turbo Pascal -Delphi - Freepascal version ...

Read More

Pascal user Manual and report Fourth Edition

Added the scan of the Pascal user Manual and report Fourth Edition, the ISO standard.

Read More

1978 KIM-1 Pascal-M

KIM-1 Pascal-M 1978 interpreter Short userguide 0. You need two cassette recorders under Micro Ade software control, see Micro Ade userguide how ...

Read More

Pascal-M 1978 Cross compiler

The original 1978 version of Pascal-M, a P2 descendent, has been restored. Original source, which can compile itself, is now ...

Read More


DSC_3541
This site is about my experience with the Wirth school of languages, based on the ideas and implementations of Prof Niklaus Wirth, Kenneth Bowles, Per Brinch Hansen, colleagues, and their students. And my experience with the various variants, from the P2 and P4 compilers originating in Zürich ETH, via UCSD Pascal P-System to the Borland compilers and Modula and Oberon systems. All applicable to small computers and device control.

On this website you will find information on Pascal for small machines, like Wirth compilers, the UCSD Pascal system, many scanned books and other files on UCSD Pascal, Pascal on MSX and CP/M, Delphi programming on PC, Freepascal and lazarus on Windows and Raspberry Pi, Oberon systems.

Timeline of my exposure to the Wirth language and OS and systems family, 5 years as student, 10 years as software engineer, hobby, 40 years as the way of programming!

  • WIRTH (1)1970- Pascal compilers, the P2-P4 compilers, Pascal-S, student VU Pascal (the forerunnner of the Amsterdam Compiler Kit), Andrew Tanenbaum, Professor R.P  van de Riet.
  • 1980 – UCSD P-System, Turbo Pascal, Pascal-M, 10 years VAX/VMS Pascal programmer, teacher of the Teleac support course Pascal, teacher and examinator Exin/Novi T5 Pascal
  • 1990 – Turbo Pascal 3 on CP/M to Delphi on Windows
  • 2010 – Freepascal + Lazarus on Windows and Linux

Enjoy, Hans Otten