This chapter illustrates quickly how to get an environment for Free Pascal/SDL2 development running under Linux. Attention: The following instruction may work for many Debian and Ubuntu based Linux distributions, others probably need different installation procedures.
In contrast to the Windows, in Linux there are so many variables according to the operation system (thousands of different distributions) that there can’t be a more or less generalized way how to install it. Anyway I’d like to demonstrate how it worked for me and give some hints which may help you to install it to your favorite distribution of Linux.
The distribution and software I used:
- Linux Distribution: Linux Mint 17.2 (Ubuntu/Debian based)
- Desktop: Cinnamon Desktop
- Lazarus 1.6 (installed from .deb file)
- FPC 3.0.0 (installed from .deb file)
- FPC 3.0.0 Source Code (installed from .deb file)
- Tim Blume’s SDL2 units (header translation)
- SDL2, SDL2_image, SDL2_ttf dynamic library files (Linux has .so files instead of .dll files)
Download and install FPC, FPC sourc code and Lazarus
The first step is to install the Free Pascal compiler (version 3.0.0 or higher), the Compiler’s source code (same version as the compiler) and the Lazarurs IDE (version 1.6 or higher). First check if your package manager provides this software in these (or higher) versions! It is likely that you find the software but the versions may lack behind. If that is the case, download and execute these three .deb files in the shown sequence.
Again Careful: These files are right for many Debian and Ubuntu based distributions (like Linux Mint) but may be wrong for others. Try to find out the right ones for your Linux.
- Download source: http://lazarus-ide.org (find the download button)
If everything went right, Lazarus can be started up by typing “startlazarus” in the terminal or by finding the program here: /usr/bin/startlazarus which is a symbolic link to the actual executable here: /usr/share/lazarus/1.6/startlazarus. On your system it may be located at a different location but these are rather standard location.
Start up Lazarus
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 are:
- FPC: /usr/bin/fpc
- FPC Source code: /usr/share/fpcsrc/3.0.0 (because $(FPCVER) equals the version number, see screenshot)
Before proceeding, my suggestion is to start a new project (simple program) and try out if you are able to do a simple compilation of a very simple program. E.g. a simple writeln-statement.
As a tip you should open up Lazarus’ Console to see the output of your program and writeln commands. You can find the Console at Window > Console.
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 this location:
- SDL2 units are then here: /usr/local/share/sdl2
To copy the folder to /usr/local/share/ you usually need root permission. Also make sure the new folder allows for access to its files. In my case I had to make sure that the “root group” has access to files.
Get the SDL2 dynamic library
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 you distribution maintainer already included the files.
Find SDL2 and all necessary libraries in your distribution’s package manager. Perhaps you have a search field as shown (upper right arrow). The screenshot shows what could come up then:
As you can see, for me at this moment the SDL2 dynamic link library, version 2.0.0 (libsdl2-2.0.0) was already installed (the small green check mark indicates this in Linux Mint). Anyway, SDL2_gfx (libsdl2-gfx-1.0.0) and SDL2_image (libsdl2-image-2.0.0) weren’t installed.
Find all necessary libraries and install them. These you should install:
At least for my tutorials SDL2_gfx is not necessary but you may try it out.
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.
That’s it :-)!…. – Unfortunately I ran into troubles…
The linker doesn’t find libSDL2.so
So, what I got when I tried to run the basic SDL2 code from Chapter 3:
- /usr/bin/ld: cannot find -lSDL2
Although I installed the SDL2 dynamic link library I get the linker saying it cannot find it. When looking for sdl2 in /usr/lib and its sub-folders where dynamic link libraries are placed usually, I got these two files:
- libSDL2-2.0.so.0 (which is a symbolic link to the file below)
- libSDL2-2.0.so.0.2.0 (this is the correct file!)
Anyway, the linker expects libSDL2.so, so what can you do? – Create a symbolic link with that name. This is done in the Terminal by:
- locate SDL2: shows where SDL2 is located and how it is named (for me they were in /usr/lib/x86_64-linux-gnu)
- sudo ln -s [destination of symbolic link] [name of the symbolic link]
- sudo requires to enter the root permission password
Repeat the same for all libraries (SDL2_image, … and so on) you want to use.
Congratulation! After that, everything should run smoothly :-)! I tried chapter 3-9 and all worked well for me.
Linux specific experiences
Launching application invalid
On opening up a Lazarus project (.lpi file) and try to re-run it, I get an error window titled “Launching application invalid” which said “The launching application “”[full path including the execution file of the project]”” does not exist or is not executable.” and further “See Run -> Run parameters -> Local“.
Not sure why this is. Anyway, deleting the executable from the project folder or compiling the project before running it, fixes this issue.