Compile ZDoom on Linux

From ZDoom Wiki
Jump to: navigation, search

This tutorial will guide you on the compilation of ZDoom on Linux. Commands are shown in the tutorial that should be entered into a terminal. Commands beginning with `su` and `sudo` will require temporary root/admin privileges, as will most likely any package installation.

Install dependencies

ZDoom needs certain dependencies in order to compile. These versions are known to work with recent ZDoom versions:

  • gcc 4.0 or later
  • make
  • cmake 2.4 or later (2.8+ recommended)
  • fmodex 4.26.36
  • SDL 2.0.3
  • zlib (optional - ZDoom has a copy of it and will be statically compiled in if not found)
  • libbzip2 (optional - possibly static)
  • libjpeg (optional - possibly static)
  • nasm 2.03.90–2.05.01 or 0.98.39 (optional)
  • GTK2 (optional)
  • Mesa (if compiling GZDoom); or any other GL implementation provider. Compile GZDoom on Linux
  • gxmessage (needed to show the crash log in a window)
  • git (needed in order to clone repository)
  • fluidsynth (optional)
  • libgme or game-music-emu (optional)

You can presumably use any higher versions of these programs, however that might not be the case. FMOD Ex, notably, does not have a constant API and using a version newer than the one listed above can prevent the successful compilation or execution of ZDoom.

Debian/Ubuntu

sudo apt-get install build-essential zlib1g-dev libsdl2-dev libjpeg-dev \
nasm tar libbz2-dev libgtk2.0-dev cmake git libfluidsynth-dev libgme-dev

Fedora

yum install gcc-c++ make zlib-devel SDL2-devel libjpeg-turbo-devel \
nasm tar bzip2-devel gtk2-devel cmake git fluidsynth-devel game-music-emu-devel

Arch Linux

ZDoom is available in Arch User Repository at http://aur.archlinux.org/packages.php?ID=16403

Install as per usual for AUR packages.

pacman -S --needed gcc make zlib sdl2 libjpeg-turbo nasm tar bzip2 gtk2 cmake git fluidsynth libgme fmodex

openSUSE

zypper install gcc-c++ make zlib-devel libSDL2-devel libjpeg-devel \
nasm tar libbz2-devel gtk2-devel cmake git fluidsynth-devel libgme-devel

(FMOD available in RPM format from third-party repositories. At your option, you can also use yast2 instead of zypper.)

Mageia

if [ "$(uname -m)" = "x86_64" ]; then 
a="64" 
else
a=""
fi && \
urpmi gcc-c++ make lib"$a"zlib-devel lib"$a"SDL2-devel \
lib"$a"jpeg-devel nasm tar lib"$a"bzip2-devel \
lib"$a"gtk+2.0-devel cmake git lib"$a"fluidsynth-devel \
lib"$a"gme-devel lib"$a"cairo-devel

Gentoo

emerge -avn sys-devel/gcc sys-devel/make sys-libs/zlib media-libs/libsdl2 media-libs/libjpeg-turbo \
dev-lang/nasm app-arch/tar app-arch/bzip2 x11-libs/gtk+ dev-util/cmake dev-vcs/git media-sound/fluidsynth \
media-libs/game-music-emu

PCLinuxOS

if [ "$(uname -m)" = "x86_64" ]; then 
a="64" 
else
a=""
fi && \
apt-get install gcc-c++ make zlib1-devel lib"$a"SDL2-devel \
lib"$a"jpeg62-devel nasm tar lib"$a"bzip2-devel \
lib"$a"gtk+2.0_0-devel cmake git lib"$a"fluidsynth1-devel

Make sure the versions of these packages are equal to or greater than one of the versions listed above.

Continue to Make zdoom_build directory

Get the ZDoom sources

It is recommended that you use a recent version from the Git repository to compile, but you may use an older version's source from the ZDoom Downloads Page if desired. Note that compilation steps may differ for older versions.

Since a git clone is recommended, this guide will be referring to the root directory of the source code (not the src directory) as the "clone directory."

Get the FMOD package

ZDoom uses the FMOD Ex library for audio. In many distributions, this will need to be installed manually. Check your system's package manager first to see if FMOD Ex is supported, and install it from there if it is and skip this section. Otherwise, run the following commands to install FMOD Ex:

wget http://www.fmod.org/download/fmodex/api/Linux/fmodapi42636linux.tar.gz
tar -xvzf fmodapi42636linux.tar.gz

Note that if you are on a 64-bit system, you will want the 64-bit version; use the following commands to get that instead. (You can have both the 32- and 64-bit versions installed concurrently, and this may be desirable if you wish to be able to use FMOD Ex with both 32- and 64-bit applications.)

# to get the 64-bit version
wget http://www.fmod.org/download/fmodex/api/Linux/fmodapi42636linux64.tar.gz
tar -xvzf fmodapi42636linux64.tar.gz

Now that the library has been downloaded and extracted, you may choose to install it or place it in the ZDoom directory tree.

If you will not be installing ZDoom but running directly from the location where it is compiled, installing FMOD Ex is not strictly required, and you can place it in the clone directory or build directory. (**As installing ZDoom is not officially supported, you should probably choose this option**.) This has the advantage that you can easily have multiple versions of FMOD on your system with no conflicts between each other:

mv fmodapi42636linux /path/to/zdoom

If instead, you would like to install FMOD Ex to /usr/local, you can do so:

cd fmodapi42636linux # or fmodapi42636linux64 for the 64-bit version
sudo make install

You will be prompted for your password, and assuming you have correct administrator privileges, FMOD Ex will be installed.

Compile

ZDoom uses CMake to handle makefile generation on Linux, so simply running make will not build ZDoom until you have used CMake first.

First make sure that the zdoom directory looks something like this :-

  /games/zdoom/$ ls
  bzip2 dumb fmodapi42636linux64.tar.gz jpeg-6b specs tools  
  zdoom.vcproj CMakeLists.txt FindFluidSynth.cmake 
  game-music-emu lzma src wadsrc zlib docs
  fmodapi42636linux64 gdtoa output_sdl  strifehelp.acs  zdoom.sln

Then make sure that the git master is upto date. This can be seen by doing :-

  ~/games/zdoom$ git pull origin master
  From https://github.com/rheit/zdoom.git/
  * branch            master      -> FETCH_HEAD
  Already up-to-date.

This means that we are with the latest development version.

Next, we need to make a directory for CMake to work from, and compile to.

mkdir release
cd release

Invoke CMake to parse the ZDoom source and get ready for compiling:

cmake -DCMAKE_BUILD_TYPE=Release ..

It may be necessary to tell it where the FMOD files and includes are located, for example use this command if you installed version 4.26.36 of FMOD:

cmake -DCMAKE_BUILD_TYPE=Release -DFMOD_LIBRARY=/usr/local/lib/libfmodex-4.26.36.so -DFMOD_INCLUDE_DIR=/usr/local/include/fmodex/ ..

In case 64-bit FMOD is used, it of course needs to point to that instead.

-DFMOD_LIBRARY=/usr/local/lib64/libfmodex64-4.26.36.so

Compile the code from inside the release directory.

make

Compile with FMOD in the clone directory (AMD64)

This is the recommended method, especially for 64 bit systems, I've noticed that the installation does not usually put the file in lib64, and it was quite a hunt to find it.

This portion is for x64 machines, but it should work with i386 systems as well, if you remove the 64 in fmodapi42416linux64/ and libfmodex64-4.26.36.so it should work.

Follow the above steps, but the CMake commands will be different.

Keep in mind that the -DFMOD_LIBRARY parameter needs to point to a specific .so file (e.g., fmodapi42416linux64/api/lib/libfmodex-4.26.36.so) and -DFMOD_INCLUDE_DIR needs to point to a DIRECTORY (e.g., fmodapi42416linux64/api/inc). If you're in doubt about the locations of a file, you can open these directories up to be sure that your library is there. Your inc/ directory should include .h and .hpp files.

That is basically what these three parameters for CMake do, they tell CMake where the libraries and include files are, both libraries and includes are needed to compile ZDoom.

Your command would look like this, replace <path to clone> with the directory which the clone was created in, e.g., /home/yourname/zdoom/ and replace fmodapi<VERSION>linux64 with the version you're using. Right now I'm using the AMD64 version of FMOD 4.24.16, so my folder is fmodapi42416linux64.

(this command should be a single line, shown on two lines so it's easier to read)

cmake -DCMAKE_BUILD_TYPE=Release -DFMOD_LIBRARY=<path to clone>/fmodapi<VERSION>linux64/api/lib/libfmodex64-4.26.36.so 
-DFMOD_INCLUDE_DIR=<path to clone>/fmodapi<VERSION>linux64/api/inc ..

Start playing ZDoom

Assuming all goes well, an executable zdoom and the zdoom.pk3 file will be generated in the release directory. To start ZDoom, the following command should work:

./zdoom

If ZDoom complains you do not have any IWADs set up, make sure that you have your IWAD files placed in the same directory as ZDoom, in $HOME/.zdoom, $DOOMWADDIR, or /usr/local/share.

Troubleshooting

Sound

If ZDoom starts but immediately closes with the following messages in the terminal:

...
Init Playloop state.
Setting up sound.
S_Init
Checking network game status.
player 1 of 1 (1 nodes)

This usually indicates that FMOD Ex is not loading correctly (and ZDoom is configured to use FMOD by default). There are then two solutions.

You could start ZDoom without music:

zdoom -nomusic

or you could select (in the ZDoom settings) a MIDI device other than FMOD. To change MIDI device, go to the sound options menu.

  • ... on any Debian/Ubuntu-based distribution, run:
sudo apt-get install timidity timidity-interfaces-extra
  • ... on openSUSE:
yast2 -i timidity or zypper in timidity
  • ... on Gentoo, run:
sudo emerge -avn timidity++

See the software synthesizer article for further information about ZDoom's MIDI devices.

Developing

This page has helped you compile ZDoom, but perhaps you are interested in debugging the code or submitting code changes or fixes for inclusion. This section is intended for more advanced users who may be unfamiliar to CMake or debugging on Linux systems.

Debugging

Maybe you have found a way to make ZDoom crash, and are interested in debugging it. First, you need to compile a debug build of ZDoom. Inside the clone directory, create a new directory debug.

mkdir debug
cd debug

Invoke CMake to set up for compiling, but this time, the build type is set to Debug.

cmake -DCMAKE_BUILD_TYPE=Debug ..

After CMake is done, run make as usual.

To run ZDoom under a debugger such as gdb, use the following command:

gdb zdoom

Now gdb should have you in its own prompt. You probably want to log the output, so lets output to a file log.txt:

set logging on log.txt

Now start ZDoom by typing in run, and pressing enter. (Put any arguments to zdoom after run .) If ZDoom crashes, gdb may be able to tell you the source file and line number it crashed in. Typing in the command backtrace will produce information telling the last function calls, showing how execution got to the point where it crashed. All output will be copied into the log.txt, which can then be scrutinized later, or perhaps posted to the Bugs forum for other developers to look at.

To get out of gdb's prompt, type quit.

Build Options

CMake Build Types
Types Description Example
Debug Debug information, -O1 optimization. cmake -DCMAKE_BUILD_TYPE=Debug ..
Release No debug information, -O3 optimization. cmake -DCMAKE_BUILD_TYPE=Release ..
RelWithDebInfo Debug information, -O3 optimization. Useful for finding optimization bugs that only show up in Release. cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
MinSizeRel Similar to Release but with less optimizations in order to save space. cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..

Make zdoom_build directory

Open a terminal and copy and paste the whole code box for each step.

mkdir -pv $HOME/zdoom_build


Download the Source

Download the ZDoom source and make build directory:

cd $HOME/zdoom_build && \
git clone git://github.com/rheit/zdoom.git && \
mkdir -pv zdoom/build

and run the following commands:

cd zdoom
git config --local --add remote.origin.fetch +refs/tags/*:refs/tags/*
git pull

Download FMOD

Download FMOD 4.26.36 32-bit or 64-bit and extract files to zdoom directory:

cd $HOME/zdoom_build && \
if [ "$(uname -m)" = "x86_64" ]; then 
FMODFOLDER="fmodapi42636linux64" 
else
FMODFOLDER="fmodapi42636linux"
fi && \
wget -nc http://www.fmod.org/download/fmodex/api/Linux/$FMODFOLDER.tar.gz && \
tar -xvzf $FMODFOLDER.tar.gz -C zdoom

FMOD Links

FMOD 4.26.36 32-bit:
http://www.fmod.org/download/fmodex/api/Linux/fmodapi42636linux.tar.gz

FMOD 4.26.36 64-bit:
http://www.fmod.org/download/fmodex/api/Linux/fmodapi42636linux64.tar.gz

Compiling

cd $HOME/zdoom_build/zdoom/build && \
if [ "$(uname -m)" = "x86_64" ]; then
FMODFOLDER="fmodapi42636linux64"
FMODFILE="libfmodex64-4.26.36"
else
FMODFOLDER="fmodapi42636linux"
FMODFILE="libfmodex-4.26.36"
fi && \
make clean ; \
cmake -DCMAKE_BUILD_TYPE=Release \
-DFMOD_LIBRARY=$HOME/zdoom_build/zdoom/$FMODFOLDER/api/lib/$FMODFILE.so \
-DFMOD_INCLUDE_DIR=$HOME/zdoom_build/zdoom/$FMODFOLDER/api/inc .. && \
make

Current release version

Show the current release version:

cd $HOME/zdoom_build/zdoom && \
git describe --tags $(git rev-list --tags --max-count=1)

If you want to compile the current release version, run:

cd $HOME/zdoom_build/zdoom && \
git checkout $(git rev-list --tags --max-count=1)

and compile.

After compiling and backing up the current release version, run:

cd $HOME/zdoom_build/zdoom && \
git checkout master

Backup

Follow this step if you want or manually copy (backup) zdoom, zdoom.pk3 and liboutput_sdl.so.

Make and name a directory with the corresponding ZDoom version/revision and copy zdoom, zdoom.pk3 and liboutput_sdl.so to it:

cd $HOME/zdoom_build && \
BACKUPZDOOM="$(sed -n 's/.*#define GIT_DESCRIPTION "\(.*\)".*/\1/p' \
zdoom/src/gitinfo.h)" && \
mkdir -pv "$BACKUPZDOOM" && \
cp -v zdoom/build/{zdoom,zdoom.pk3,\
output_sdl/liboutput_sdl.so} "$BACKUPZDOOM"

Backup (Optional)

Make and name a directory with the current year, month, day, hour and minute and copy zdoom, zdoom.pk3 and liboutput_sdl.so to it:

cd $HOME/zdoom_build && \
BACKUPZD="$(date +%Y%m%d%H%M)" && \
mkdir -pv "$BACKUPZD" && \
cp -v zdoom/build/{zdoom,zdoom.pk3,\
output_sdl/liboutput_sdl.so} "$BACKUPZD"

If you did "Backup" or "Backup (Optional)", the previous files should be located at:

/home/<your username>/zdoom_build/

Updating

When you wish to update ZDoom, copy and paste the following:

cd $HOME/zdoom_build/zdoom && \
git pull

When the update finish, go to Compiling.

Installation

The following steps contain commands that require to be run as superuser with the sudo command.

If you want to install ZDoom, do the following:

Make /usr/games/zdoom directory:

sudo mkdir -pv /usr/games/zdoom

Copy zdoom, zdoom.pk3, liboutput_sdl.so and libfmodex64-4.26.36.so or libfmodex-4.26.36.so to /usr/games/zdoom:

if [ "$(uname -m)" = "x86_64" ]; then
FMODFOLDER="fmodapi42636linux64"
FMODFILE="libfmodex64-4.26.36"
else
FMODFOLDER="fmodapi42636linux"
FMODFILE="libfmodex-4.26.36"
fi && \
sudo cp -v /home/$USER/zdoom_build/zdoom/{build/{zdoom,\
zdoom.pk3,output_sdl/liboutput_sdl.so},\
$FMODFOLDER/api/lib/$FMODFILE.so} /usr/games/zdoom

Make zdoom script, add executable permission and copy it to /usr/bin:

cd /tmp && \
echo '#!/bin/sh' > zdoom && \
echo >> zdoom && \
echo 'export LD_LIBRARY_PATH=/usr/games/zdoom' >> zdoom && \
echo 'exec /usr/games/zdoom/zdoom "$@"' >> zdoom && \
chmod 755 zdoom && \
sudo cp -v zdoom /usr/bin && \
rm -fv zdoom

Now from a terminal you should be able to execute zdoom from any user account.

Uninstallation

To remove the previous installation steps:

Remove /usr/games/zdoom directory and all its files:

cd /usr/games && \
sudo rm -rfv zdoom

Remove zdoom script:

cd /usr/bin && \
sudo rm -fv zdoom

External links