Skip to content

Compiling games with SDL2

LucaFeggi edited this page Feb 2, 2024 · 12 revisions

(These are the steps followed for a Raspberry Pi 4 with 2 GB of memory running Raspberry OS "bookworm" as the user "pi".)

Prepare system

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

$ cat /etc/debian_version
12.4

sudo apt update
sudo apt full-upgrade
sudo apt -y install cmake

Check default SDL2 packages

sudo apt list --installed | grep sdl2

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libsdl2-2.0-0/stable,now 2.26.5+dfsg-1 arm64 [installed,automatic]
libsdl2-image-2.0-0/stable,now 2.6.3+dfsg-1 arm64 [installed,automatic
libsdl2-mixer-2.0-0/stable,now 2.6.2+dfsg-2 arm64 [installed,automatic]
libsdl2-ttf-2.0-0/stable,now 2.20.1+dfsg-2 arm64 [installed,automatic]

Install SDL2 development packages

sudo apt -y install libsdl2-dev
sudo apt -y install libsdl2-image-dev
sudo apt -y install libsdl2-mixer-dev
sudo apt -y install libsdl2-ttf-dev

sudo apt list --installed | grep sdl2-dev

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libsdl2-dev/stable,now 2.26.5+dfsg-1 arm64 [installed]
libsdl2-image-dev/stable,now 2.6.3+dfsg-1 arm64 [installed]
libsdl2-mixer-dev/stable,now 2.6.2+dfsg-2 arm64 [installed]
libsdl2-ttf-dev/stable,now 2.20.1+dfsg-2 arm64 [installed]

Clone Arcade git repository to system

cd ~/Documents
git clone https://github.com/TheSaturdayThing/Arcade.git

Build and run "Test" program

cd ~/Documents/Arcade/src/Test
mkdir build
cd build
cmake ..
make
./Test

image

Build and run "Pong" program

cd ~/Documents/Arcade/src/Pong
mkdir build
cd build
cmake ..
make
cd ..
ln -s build/Pong .
./Pong

image

Build and run "PacMan" program

cd ~/Documents/Arcade/src/PacMan
mkdir build
cd build
cmake ..
make
cd ..
ln -s build/Pacman .
./PacMan

image