This chapter illustrates quickly how to set up a Free Pascal and SDL2 development environment within a few minutes under Linux.
Attention: The following instruction particularly work for many Debian and Ubuntu based Linux distributions (like Linux Mint used here). In general it outlines the way to go, though.
The distribution and software I used:
- Linux Distribution: Linux Mint 19.3 (Ubuntu/Debian based)
- Desktop: Cinnamon Desktop
- Lazarus 2.0.6 (installed from .deb file)
- FPC 3.0.4 (installed from .deb file)
- FPC 3.0.4 Source Code (installed from .deb file)
- Tim Blume’s SDL2 units (header translation)
- SDL2, SDL2_image, SDL2_ttf shared object files (from distro’s package manager)
Download and install FPC, FPC sourc code and Lazarus
The first step is to install the Free Pascal compiler (version 3.0.4 or higher), the Compiler’s source code (same version as the compiler) and the Lazarurs IDE (version 2.0.6 or higher). To get the most recent, stable environment, download these three files from the official Lazarus website: https://www.lazarus-ide.org/index.php?page=downloads.
Important: Do not intermix FPC or Lazarus installs from the package manager. This will lead to troubles because these installs are not compatible. Purge any of these installs. Use, e.g.:
dpkg --list (show all installed packages)
sudo apt-get --purge fp-compiler.... [exact package name] (remove package incl. config files)
Choose one of the “Linux DEB Releases” according to your system (32 bit or 64 bit). Most probably your running on a 64 bit system, which is the standard case for Linux.
In case of a 64 bit system download these three files:
The download page looks somewhat like this:
If you downloaded these three files successfully, you run them in the same order! First FPC, then FPC’s sources and finally Lazarus.
If everything went right, Lazarus can be started up by typing “startlazarus” in the terminal or by finding the program in the application menue.
Start up Lazarus the first time
On start up of Lazarus the directories for FPC and the FPC source code were found and set already. As a hint I show where these are located on my system:
- FPC: /usr/bin/fpc
- FPC Source code: /usr/share/fpcsrc/3.0.4 (because $(FPCVER) equals the version number, see screenshot)
The configurations screen may look somewhat different to the screen of the following screenshot, but that is because the screenshot is outdated a bit.
Before proceeding, my suggestion is to simply compile the project (press F9 in Lazarus) which is presented to you. It should compile and show the form.
Get the SDL2 units
Get the latest version of the translated SDL2 units.
Make sure you have the master branch chosen and then click on “Clone or download”, then “Download ZIP”.
After extracting the ZIP file I suggest to rename the new folder into “sdl2” or “SDL2” and place it at any location, perhaps your development folder, e.g.:
- ~/projects/sdl2 (a.k.a /home/[username]/projects/sdl2)
- (DO NOT use the suggested folder in the screenshot)
Get the SDL2 shared object files
If you are looking for the most recent pre-compiled SDL2 dynamic link library files (e.g. libSDL2.so) on the official SDL2 website, you just find a remark that reads like this:
Please contact your distribution maintainer for updates.
Since SDL2 is very widespread it is very likely that your distribution maintainer already included the files.
Find SDL2 and all necessary libraries in your distribution’s package manager, here it is the synaptic package manager. Look for libsdl and install every package shown in the screenshot:
Find all necessary libraries and install them. These you should install:
The dev-packages are necessary to compile sdl2 applications. The other packages are necessary to run sdl2 applications.
The version of these libraries does not necessarily need to be the most recent unfortunately. If you really need the most recent versions here, you may try to contact the maintainer to ask to update the version.
Congratulation! After that, everything should run smoothly :-)!