Running FreeBASIC on Raspberry Pi

Hey! This is yet another of my ancient posts about Raspberry Pis that probably contains out-of-date information. In order to run FreeBASIC on a Raspberry Pi, all you need do is:

  1. Download a nightly build
  2. Unpack it and run the installer.

That’s it! You can access GPIO with FreeBASIC, too: GPIO LED Blink using FreeBASIC and WiringPi

FreeBASIC is a pretty nifty cross-platform BASIC compiler. It uses a Microsoft-like syntax, has an active user and developer base, and is quite fast. Building the latest version on a Raspberry Pi is a bit of a challenge, though.

FreeBASIC 1.01 demo running on a Raspberry Pi
FreeBASIC 1.01 demo running on a Raspberry Pi from Geany

Part of the problem is that FreeBASIC is mostly written in FreeBASIC, so you need a working compiler to bootstrap the latest version.

Update: you’re probably best just downloading the binary install packages from the FreeBASIC site. I’m having difficulty getting recent (late 2016) source packages to build for reasons that would take too long for most people to care about.

The following steps worked for me:

  1. Install some necessary packages:
    sudo apt-get install build-essential libncurses5-dev libffi-dev libgl1-mesa-dev libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev ncurses-doc libxcb-doc libxext-doc libgpm-dev git libcunit1 libcunit1-dev libcunit1-doc

    (You don’t really have to include the cunit packages; they’re only needed if you run tests before installation.)

  2. Download a nightly binary from Sebastian’s server: http://users.freebasic-portal.de/stw/builds/linux-armv6-rpi/  and install it:
    unzip fbc_linux_armv6_rpi_version.zip
    cd fbc_linux_armv6_rpi/
    chmod +x install.sh
    sudo ./install.sh -i

    Don’t delete the installation folder just yet.

  3. Grab the latest version of the source from github:
    cd
    git clone https://github.com/freebasic/fbc.git

    Change directory to the new FreeBASIC source folder (cd fbc), and type make. (or, on a Raspberry Pi 2 or 3, make -j4 to use all the cores …). After a while (in my tests, about 52 minutes on a 512 MB Raspberry Pi, or around 6½ minutes [!] on a Raspberry Pi 2), it should finish. If there’s a bin/fbc file, the compilation worked!

  4. Before you install the new compiler, uninstall the old one: change directory to the fbc_linux_armv6_rpi folder, and type:
    sudo ./install.sh -u
  5. Once that’s done, go back to the new fbc folder, and type:
    sudo make install

And you’re done! You can delete the fbc_linux_armv6_rpi folder now. If you don’t mind it taking up space, keep the fbc folder to allow you a quick rebuild of the latest version of the compiler with:

cd fbc
git pull
make
sudo make install

Note that this will build a native armv7l compiler on a Raspberry Pi 2, and an armv6l one on a Raspberry Pi. This means you can’t run binaries you built on a Raspberry Pi 2 on a Raspberry Pi (you’ll get an Illegal Instruction error), but you should be able to run ones built on a Raspberry Pi on a Raspberry Pi 2. Binary compatibility is overrated, anyway …

9 comments

  1. Hi ! Thanks for writing this. I just followed your guide on my Raspberry Pi 1 Model B with 512mb. Everything worked fine at first. But then I tried to compile a simple hello world example and when I tried to execute it, I got an ‘Illegal Instruction’ error. That’s really strange, because the compiler runs fine with armv6 obviously. But it generates code for armv7 by default. I tried starting the compiler with “fbc -arch armv6l test.bas”, but then I get:

    error 80: Invalid command-line option, “-arch armv6l”

    Can someone enlighten me ?

  2. Thanks. I figured out it works with “-arch armv6″ without the ‘l’.

  3. I’m getting an error when building fbc, it is a problem with the include gpm.h. I’ve searched my system, and sure enough, there is no gpm.h anywhere. I do have libgpm2 installed, but apparently no headers to go with it. I’ve tried installing stuff like libgpm2-dev, but that meets with a package not found error, so where the heck is this gpm.h file, (the url you gave above of where to get it is broken).
    Any help would be appreciated.

  4. Travis, did you install all of the packages I listed in the apt-get line in step 1? Your missing file is in the libgpm-dev package.

  5. Hi! I’m just wondering why you rebuild the compiler to install it instead of just using the nightly build straight away. The nightly build is already built from the most recent GIT sources and additionally contains a patch that changes the default architecture to armv6. There are also builds for armv7 (rpi2) available. The nightly build packages do not contain additional stuff like documentation and additional headers. You can either grab these from github or from separate packages on the nightly build downloads site.

  6. Well, when I wrote that comment, I would have sworn on a stack of bibles that I had installed all of the above mentioned packages. This is my third rebuild of my system, due to loosing sd cards (among other things) and this time, I made sure to install everything, and it worked perfectly. Sorry for the trouble, and thanks for the info on how to do this.

  7. Thank you for the info. I decided for now to stick to the nightly build, it works well and I do not need the latest version, though the info is good if I ever do need a self built version.

    fbc runs well on the RPi 3B, and so does the quick “Hello World!” program that has been a mainstay of trying new BASIC compilers for me:

    ScreenRes 640,480,16

    LINE (0,0)-(639,239),RGB(0,0,255),bf
    While (inkey$=””):Wend

Leave a comment

Your email address will not be published. Required fields are marked *