Freepascal for Raspberry Pi
Freepascal is an excellent open source object pascal compiler available for many platforms. For more information, please see the official Freepascal website.
I use it in many of my projects, especially embedded projects on Raspberry Pi single board computers. However it is not well maintained on that platform.
Often the official builds of Freepascal for Raspbian are out of date - sometimes severely so. Raspbian Jessie was stuck at version 2.6. Raspbian Stretch now has 3.0.0 available, but how regularly will it be updated to track the official Freepascal releases? I suspect not very often based on the past.
I have figured out how to build my own installers/distributions of Freepascal for the Raspberry Pi, and will aim to track official FPC releases.
Important
My releases do not have working debugging / gdb support, as I cannot figure out how to satisfy that part of the build process. It requires the correct version of libgdb assembly files which I cannot locate. For most people this will not matter - the compiler and libraries work perfectly. The only broken/missing functionality is the debugging built into the IDE which you don't really need.
Releases
The current release is v3.0.4 [2017/12/10]
Freepascal for Raspberry Pi releases page - click here
Installation instructions
Transfer the file to your Raspberry Pi, or download it using wget. Then login, unpack and run install.sh as root using sudo. Here is an example session. Please make sure you grab the latest version, don't blindly copy the commands.
~ $ mkdir install ~ $ cd install/ ~/install $ wget https://media.zipplet.co.uk/fpc-rpi/fpc-3.0.2.arm-linux.tar <snip> ~/install $ tar -xvf fpc-3.0.2.arm-linux.tar fpc-3.0.2.arm-linux/ fpc-3.0.2.arm-linux/binary.arm-linux.tar fpc-3.0.2.arm-linux/install.sh fpc-3.0.2.arm-linux/doc-pdf.tar.gz fpc-3.0.2.arm-linux/demo.tar.gz ~/install $ cd fpc-3.0.2.arm-linux/ ~/install/fpc-3.0.2.arm-linux $ sudo ./install.sh
The screen then clears, and you'll see the installation screen. It is recommended you choose /usr/local for the installation path. Here is my session. Tar might warn about lone zero blocks, but the installer works anyway. If you are a maintainer of freepascal and know what I'm doing wrong, please let me know so that I can remove this warning from my installers. Thank you!
This shell script will attempt to install the Free Pascal Compiler version 3.0.2 with the items you select Install prefix (/usr or /usr/local) [/usr] : /usr/local Installing compiler and RTL for arm-linux... Installing rtl packages... Installing rtl-console Installing rtl-extra Installing rtl-objpas Installing rtl-unicode Installing fcl... Installing fcl-async Installing fcl-base Installing fcl-db Installing fcl-extra Installing fcl-fpcunit Installing fcl-image Installing fcl-js Installing fcl-json Installing fcl-net Installing fcl-passrc Installing fcl-pdf Installing fcl-process Installing fcl-registry Installing fcl-res Installing fcl-sdo Installing fcl-sound Installing fcl-stl Installing fcl-web Installing fcl-xml Installing packages... Installing a52 Installing aspell Installing bfd Installing bzip2 Installing cairo Installing cdrom Installing chm Installing dblib Installing dbus Installing dts Installing fastcgi Installing fftw Installing fpgtk Installing fpindexer Installing fpmkunit Installing fppkg Installing fv Installing gdbint Installing gdbm Installing ggi Installing gmp Installing gnome1 Installing googleapi Installing gtk1 Installing gtk2 Installing hash Installing hermes Installing httpd22 Installing httpd24 Installing ibase Installing iconvenc Installing imagemagick Installing imlib Installing jni Installing ldap Installing libcurl Installing libgd Installing libmicrohttpd Installing libpng Installing libsee Installing libtar Installing libvlc Installing libxml2 Installing lua Installing mad Installing modplug Installing mysql Installing ncurses Installing newt Installing numlib Installing odbc Installing oggvorbis Installing openal Installing opengl Installing opengles Installing openssl Installing oracle Installing pasjpeg Installing paszlib Installing pcap Installing postgres Installing proj4 Installing ptc Installing pthreads Installing pxlib Installing regexpr Installing rsvg Installing sdl Installing sqlite Installing svgalib Installing symbolic Installing syslog Installing tcl Installing unzip Installing users Installing utmp Installing uuid Installing x11 Installing xforms Installing zlib Installing zorba Installing utilities... Installing utils Installing fpcm Installing fpcmkcfg Installing fpcres Installing fpdoc Installing fppkg Installing fprcp Installing h2pas Installing instantfpc Installing lexyacc Installing pas2fpm Installing pas2jni Installing pas2ut Installing unicode Install Textmode IDE (Y/n) ? y tar: A lone zero block at 8729 Done. Install documentation (Y/n) ? y Installing documentation in /usr/local/share/doc/fpc-3.0.2 ... Done. Install demos (Y/n) ? y Install demos in [/usr/local/share/doc/fpc-3.0.2/examples] : Installing demos in /usr/local/share/doc/fpc-3.0.2/examples ... Done. Running on linux Write permission in /etc. Writing sample configuration file to /etc/fpc.cfg Saved old "fpc.cfg" to "fpc.bak" Writing sample configuration file to /usr/local/lib/fpc/3.0.2/ide/text/fp.cfg Saved old "fp.cfg" to "fp.bak" Writing sample configuration file to /usr/local/lib/fpc/3.0.2/ide/text/fp.ini Saved old "fp.ini" to "fp.bak" Writing sample configuration file to /etc/fppkg.cfg Saved old "fppkg.cfg" to "fppkg.bak" Writing sample configuration file to /etc/fppkg/default Saved old "default" to "default.bak" End of installation. Refer to the documentation for more information.
Testing the compiler
First, just run fpc and make sure you get sensible output like this with the version you downloaded:
~/install/fpc-3.0.2.arm-linux $ fpc Free Pascal Compiler version 3.0.2 [2017/11/19] for arm Copyright (c) 1993-2017 by Florian Klaempfl and others /usr/local/bin/fpc [options] <inputfile> [options] Only options valid for the default or selected platform are listed. Put + after a boolean switch option to enable it, - to disable it. @<x> Read compiler options from <x> in addition to the default fpc.cfg -a The compiler does not delete the generated assembler file -al List sourcecode lines in assembler file -an List node info in assembler file (-dEXTDEBUG compiler) -ao Add an extra option to external assembler call (ignored for internal) -ap Use pipes instead of creating temporary assembler files -ar List register allocation/release info in assembler file -at List temp allocation/release info in assembler file -A<x> Output format: -Adefault Use default assembler -Aas Assemble using GNU AS -b Generate browser info -bl Generate local symbol info -B Build all modules -C<x> Code generation options: -C3 Turn on ieee error checking for constants -Ca<x> Select ABI; see fpc -i or fpc -ia for possible values *** press enter ***
If you do, create a file called helloworld.dpr using nano, vim or your favourite editor containing:
program helloworld; begin writeln('Hello, world'); end.
Now compile it by typing fpc helloworld.dpr and you should see something like this:
~/install/fpc-3.0.2.arm-linux $ fpc helloworld.dpr Free Pascal Compiler version 3.0.2 [2017/11/19] for arm Copyright (c) 1993-2017 by Florian Klaempfl and others Target OS: Linux for ARMHF Compiling helloworld.dpr Assembling helloworld Linking helloworld /usr/bin/ld: warning: link.res contains output sections; did you forget -T? 5 lines compiled, 1.4 sec
Great. Execute it.
~/install/fpc-3.0.2.arm-linux $ ./helloworld Hello, world
Now you have a recent version of freepascal on your Raspberry Pi. Enjoy it :)
How do I build Freepascal myself?
I'm glad you asked. Information on this is hard to find, so I have written a build guide to do it yourself for the Raspberry Pi. I hope you find it useful! I might add build guides for other platforms later.
Help me maintain these builds!
If this helped you out, I'm happy it did. That's enough satisfaction for me. However if you'd like to donate towards my projects, website hosting fees and continuing this work, please see my donations page for instructions. Thank you.