This page describes how to make a stand-alone version of your Dragonfly game for Linux, as needed for the Stand-alone Game part of the Project 3 promotional materials. The result is a zipped folder that, when extracted, lets the player run your compiled game from the command line - no source code, engine or SFML install needed.
In the examples below, the game is called my-game.
Replace that with the name of your game.
For other platforms, see Mac or Windows.
When done, your stand-alone game folder should look like:
my-game/
my-game <- release binary
run.sh <- launcher script
df-font.ttf
sprites/
sounds/
lib/ <- SFML .so files
Build a Release version of your game using the release version of the SFML libraries and a release version of Dragonfly, as appropriate.
Make a new, empty folder, with a lib/ folder inside
it.
mkdir -p my-game/libCopy in the executable, the Dragonfly font file and the needed sprites and sounds.
cp path/to/build/my-game my-game/
cp -R df-font.ttf sprites sounds my-game/Copy the SFML libraries into lib/. If you installed
SFML with your package manager, they are usually in
/usr/lib/ (or /usr/lib/x86_64-linux-gnu/). If
you built SFML yourself, they are in SFML/lib/. Use
ldd to see which ones your game needs, and where they
are:
ldd my-game/my-game | grep sfml
Copy each file it lists (e.g., libsfml-graphics.so.3.1),
using cp -L so you copy the actual files and not symlinks.
For example:
for l in graphics window system audio; do
cp -L ~/src/SFML/lib/libsfml-$l.so.3.1 my-game/lib/
doneAdd a launcher script, my-game/run.sh. Dragonfly
loads the sprites, sounds and font from the current directory (and
writes dragonfly.log there), so the script changes to the
game folder first. It also sets LD_LIBRARY_PATH so the game
finds the SFML libraries in lib/.
#!/bin/sh
cd "$(dirname "$0")" || exit 1
LD_LIBRARY_PATH="$PWD/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
exec ./my-game "$@"Make sure the game and script can be run, then zip up the folder
(-y keeps any symlinks as symlinks).
chmod +x my-game/my-game my-game/run.sh
zip -ry my-game.zip my-gameTip! The SFML libraries themselves depend on some
system libraries (e.g., X11, OpenGL and, for SFML 2, OpenAL, FreeType
and Vorbis). To see if any are missing on a computer, run
ldd my-game/lib/*.so* | grep "not found". Anything listed
can be installed with the package manager (see below).
Tip! Build on the oldest Linux distribution you can.
A game built on a newer system may fail on an older one with an error
like version `GLIBCXX_3.4.32' not found.
Make sure to test the installation by extracting in a different location (ideally, on another computer without SFML) and verifying it can run!
mkdir /tmp/test && cd /tmp/test && unzip ~/path/to/my-game.zip
./my-game/run.sh
To check that the game is using the bundled libraries, run:
cd my-game && LD_LIBRARY_PATH=lib ldd ./my-game | grep sfml
Each SFML library should point to lib/ in the game
folder.
Include these steps (e.g., in a README) with your zipped game.
Download and extract my-game.zip.
unzip my-game.zipRun the game:
path/to/my-game/run.shIf the game fails with an error about a missing library (e.g.,
libGL.so.1: cannot open shared object file), install it
with your package manager. For example, on Ubuntu or Debian:
sudo apt install libgl1 libx11-6 libxrandr2 libxcursor1 libxi6 libudev1