IMGD 3000 Stand-alone Game for Linux

Packaging a Dragonfly Game


Top   |   Layout   |   Package   |   Test   |   Player

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.


Top   |   Layout   |   Package   |   Test   |   Player

Folder Layout

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

Top   |   Layout   |   Package   |   Test   |   Player

Package

  1. Build a Release version of your game using the release version of the SFML libraries and a release version of Dragonfly, as appropriate.

  2. Make a new, empty folder, with a lib/ folder inside it.

    mkdir -p my-game/lib
  3. Copy 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/
  4. 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/
    done
  5. Add 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 "$@"
  6. 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-game

Tip! 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.


Top   |   Layout   |   Package   |   Test   |   Player

Test

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.


Top   |   Layout   |   Package   |   Test   |   Player

Instructions for the Player

Include these steps (e.g., in a README) with your zipped game.

  1. Download and extract my-game.zip.

    unzip my-game.zip
  2. Run the game:

    path/to/my-game/run.sh
  3. If 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

Top   |   Layout   |   Package   |   Test   |   Player

Return to Project 3