Difference between revisions of "The Dark Mod - Compilation Guide"

From The DarkMod Wiki
Jump to navigationJump to search
m (add Debian instructions)
(add symlink)
Line 62: Line 62:
It might also be necessary to make the following symlink:
ln -s /lib32/libpng12.so.0 /lib32/libpng.so
=== Ubuntu 10.10 64 Bit ===
=== Ubuntu 10.10 64 Bit ===

Revision as of 21:07, 14 October 2012

This guide should provide you with enough information to compile The Dark Mod's game code from source.

The sources are available through "snapshots", i.e. whenever the Dark Mod team is releasing a new update (e.g. TDM 1.01) the corresponding sources are released as well.

Download the sources

You can download the latest source package from our website: http://www.thedarkmod.com/download_source.php


For Windows you'll need Visual Studio to compile the project, you can get the free Express editions from the Microsoft website. It should work with every version starting from VC++ 2008 upwards. (Note: you don't need a Platform SDK for VC++ 2008).

Download the sources and unpack them somewhere. You'll find a d3game.sln solution file (which is in VC++ 2008 format), which you can double-click to open in Visual Studio.

Once opened, select the Configuration Type in the topmost toolbar (either "release" or "debug", depending on what you want to do) and hit "Build Solution" (Ctrl-Shift-B). The compilation usually takes a few minutes, watch the output window at the bottom of Visual Studio. Once completed, you'll find the compiled gamex86.dll in a subfolder named "releasedll" (for release builds" or "debugdll" (for debug builds).

In order to "install" the gamex86.dll, you need to copy it somewhere where Doom3.exe can find it. There are two ways to do that: either you place the dll right next to your DOOM3.exe which will override any other mechanism (the game will always load the DLL right next to DOOM3.exe first), or you put them in a PK4 (along with a binary.conf file) and place it in your mod folder. There is some info on www.iddevnet.com/doom3 about how to do that.

Debugging the Game

To debug your custom built game code, you need to attach Visual Studio's debugger to the Doom3.exe process. There are two ways to accomplish that:

The quick one:

  1. Go to Visual Studio and open the d3game solution
  2. Start the game (either through tdmlauncher.exe or through DOOM3.exe plus command lines)
  3. Once the game is up and running, Alt-Tab back to Visual Studio
  4. Go to menu "Debug" > "Attach to Process..." and select the DOOM3.exe process from the list in that dialog popping up.
  5. The debugger will now attach to Doom3 (along with all loaded DLLs) and you can now place breakpoints or intercept game crashes.

The longer one (if you debug your game more than once or twice):

  1. Go to Visual Studio and open the d3game solution
  2. Right-click the Solution in the "Solution Explorer" and select "Add" > "Existing Project..."
  3. Browse to DOOM3.exe and select that, you'll see the DOOM3.exe project added to your solution explorer view.
  4. Right-Click the DOOM3.exe and choose "Select as startup project".
  5. Now you can start the debugger just by hitting F5 and Visual Studio will automatically attach to the Doom3 process.
  6. [Optional]: You can specify command line parameters to Doom3.exe by opening the Doom3.exe project properties and adding the desired parameters (e.g. com_allowConsole or fs_game_base/fs_game) to the "Command Arguments" item. This is necessary if you want to debug a specific TDM mission (although in this case, employing the "quick" method above is easier).

Note: you can still attach your debugger to any running DOOM3.exe process with the second method.

In Visual Studio Express 2010 (and later), you will first need to switch to Expert Settings via "Tools > Settings" to enable the "Debug" > "Attach to Process" option.


My breakpoints don't work (they are hollow circles instead of full ones)
Check if you copied the correct gamex86.dll to the folder where DOOM3.exe is located. The code you're viewing and the DLL loaded by DOOM3.exe must match exactly, otherwise Visual Studio won't load your symbols. Make sure that the configuration type (release or debug build) is matching as well. Also make sure that the code is properly compiled, e.g. hit "Build Solution" again - the output window should tell you that everything is up to date.
I cannot inspect all the variables / The instruction pointer is skipping code
You are probably running a release build, which comes with some optimisations. When debugging a release build, you'll notice that your instruction pointer (the yellow arrow) is sometimes skipping statements, which have most likely been optimised out of the binary during compilation/linking. You'll also have troubles when trying to inspect temporary variables or inlined functions. Use a debug build if this prevents you from figuring out things during debugging.


For Linux you'll need gcc and scons, plus a few packages depending on your distribution. There is a README.linux file contained in the source package you downloaded, check it out for some details.

Debian Sqeeze 64 bit

You need the following packages:

apt-get install ia32-libs scons g++ g++-multilib m4
apt-get install libglew1.5-dev libpng12-dev libjpeg62-dev
apt-get install libc6-dev-i386 libxxf86vm-dev libopenal-dev libasound2-dev

You also might edit sys/scons/SConscript.game and add the following lines near where local_env.Append is alread used:

local_env.Append(LIBS = [

It might also be necessary to make the following symlink:

ln -s /lib32/libpng12.so.0 /lib32/libpng.so

Ubuntu 10.10 64 Bit

You'll need the same packages as for the 32 bit Ubuntu variants, plus a few additional 32 bit compatibility packages (ia32-libs and libc6-dev-i386):

sudo apt-get install g++ scons libglew1.5-dev libpng12-dev libjpeg62-dev ia32-libs libc6-dev-i386

Then just run the scons command to start compiling:

scons BUILD="release" BUILD_GAMEPAK="1"

Ubuntu 10.04 32 Bit

After setting up a clean 10.04, these are the packages needed to get the source to compile. Copy & paste the following line:

sudo apt-get install g++ scons libglew1.5-dev libpng12-dev libjpeg62-dev

Then run this command to start compiling:


If the build fails, complaining that it can't find something, it needs more libraries. Execute the following line:

sudo apt-get install m4 libxxf86vm-dev libopenal-dev libasound2-dev g++-multilib gcc-multilib zlib1g-dev libxext-dev

That should install all packages needed.

Ubuntu 9.10 x64

This information about compiling in x64 builds needs to be reviewed

I had to install the following packages in Ubuntu 9.10 x64 to compile The Dark Mod's source:

scons 1.2.0
g++ 4.4.1

While the boost headers from the Ubuntu repository work fine, all the libboost-*-dev binaries (which are 64 bit) won't work for the game code (which is 32 bit). Hence I had to track down and download a few packages on my own and extract the corresponding .a file from the .deb. I then placed the static libs in the /linux/boost/lib folder and adjusted the sconscript.game.

Note: the following won't be needed in TDM source versions 1.01 and higher as the boost and libstdc++ libs will already be included in newer source packages. In these newer packages you just need to open sys/scons/SConscript.game and uncomment three lines at the bottom of the script (I left a comment there about Ubuntu 9.10).

If you're trying to compile the 1.00 package, you'll need to download the binaries, I got mine from here: http://sb.itc.u-tokyo.ac.jp/DEBIAN/pool/main/b/boost1.38/?C=M;O=A


The actual version behind the 1.38.0 can vary, just be sure to get a boost 1.38 dev package from somewhere. Open it with the Archive Manager, open the contained data.tar.gz and extract the ./usr/lib/libboost_filesystem-mt.a (or libboost_system-mt.a) file. Remove the -mt part from the name and put these files into your darkmod_src/linux/boost/lib, so that you end up with the following files in there:


Then fetch the libstdc++6_4.4.1-4ubuntu8_i386.deb file from any server you can find (I got mine from http://de.archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.4/, the actual version "ubuntu8" might be different for you), right-click the file and open it with the Archive Manager, extract the libstdc++.so.6.0.13 file and rename it to libstdc++.so. Put that file in a newly created linux/libstdc/ folder.


As next step, adjust the sconscript.game file (which is located in sys/scons/SConscript.game and scroll down towards the end of the script. There is a section defining the LIBS to be linked into the game module.

# Use static Boost and DevIL
local_env.Append(LIBS = [
    File('#/linux/boost/lib/libboost_filesystem.a'),   # ADD THIS ONE
    File('#/linux/boost/lib/libboost_system.a'),       # ADD THIS ONE
    File('#/linux/libstdc/libstdc++.so')               # ADD THIS ONE

Be sure to add the three lines marked with ADD THIS ONE. You should now be able to compile the code, and there will a tdm_game02.pk4 file created in the root folder of your source directory. Copy that file to your ~/.doom3/darkmod installation and launch the game.

Mac OS X

For OS X you'll need gcc and scons, as with Linux. gcc should be included in your xcode installation, scons can be downloaded from the scons project website. The third-party libraries like boost, devil and libcurl are already included in the TDM source package, so it should compile out of the box. If you ever need to build one of them from scratch, see the subsections below.

The sconscripts are prepared for both Intel and PPC target architectures, the MACOSX_TARGET_ARCH argument will control which architecture you're compiling for.

Compiling for Intel architecture

To start compiling, enter the following command in the folder you extracted the TDM sources to:


Compiling for PPC architecture

To start compiling, enter the following command in the folder you extracted the TDM sources to:


Compiling a universal binary

I've been using the following script to generate a universal binary. This script assumes that there are two separate TDM source folders, one in darkmod_src.i386 and one in darkmod_src.ppc. Note: they are actual copies of the same TDM source package, I just used that as convenience such that I don't have to recompile the whole source tree after minor changes.

cd /Users/greebo
cd darkmod_src.i386
cd ../darkmod_src.ppc
cd ../darkmod_src.i386
lipo -arch i386 gamei386-base.dylib -arch ppc ../darkmod_src.ppc/gameppc-base.dylib -create -output game.dylib
zip -d tdm_game03.pk4 game.dylib
zip tdm_game03.pk4 game.dylib

After this the darkmod_src.i386/tdm_game03.pk4 should contain the universal binary of the TDM game lib. The PK4 is about 6 to 7 MB.

Installing scons

Get the scons tarball from their website, unpack it to a folder and run the following commands (note that the exact scons version might differ):

cd scons-2.0.1
python setup.py install

Building libcurl in Mac OS X

Download the libcurl 7.21 source package, and extract it on your system. To produce a so-called "fat" binary you need to compile for both i386 and ppc targets.

Build the i386 target by entering:

env CFLAGS="-m32 -arch i386" LDFLAGS="-m32 -arch i386" ./configure --disable-ldap --build=i686-unknown-linux-gnu --without-libidn --without-zlib --without-ssl
sudo make install

After make install the static library can be found in /usr/local/lib/libcurl.a, copy that file to your curl folder and rename it to ./libcurl.i386.a

Build the powerpc target by entering:

env CFLAGS="-m32 -arch ppc" LDFLAGS="-m32 -arch ppc" ./configure --disable-ldap --build=powerpc-unknown-linux-gnu --without-libidn --without-zlib --without-ssl
sudo make install

After make install the static library can be found in /usr/local/lib/libcurl.a, copy that file to your curl folder and rename it to ./libcurl.ppc.a

Finally call lipo to combine these two into a fat binary by entering this in your curl folder.

lipo -arch i386 libcurl.i386.a -arch ppc libcurl.ppc.a -create -output libcurl.a

The filesize of the newly created libcurl.a should be around the sum of the single ppc and i386 libs, you can double-check that. Copy the libcurl.a into your darkmod_src/macosx/libcurl/ and you're done with this step.

Building Boost static libs in Mac OS X

Download the boost 1.45 sources and extract them to your hard drive. Create a jam user config file to use the g++ 4.0 compiler instead of the default gcc 4.2 in Leopard: create a new file in your boost root folder and name it user-config-darwin.jam:

using darwin : 8.11 : /usr/bin/g++-4.0 :
    <threading>"multi" ;

Download a bjam binary for OS X to your machine, then build boost threads, filesystem and system:

/path/to/bjam --user-config=../../../user-config-darwin.jam architecture=combined link=static threading=multi address-model=32 release [stage]

The "stage" option only works in filesystem and system (not in thread, as of boost 1.45). You'll find the filesystem and system libs in the ./stage folder of your boost root, the libboost_thread.a will be located in the bin.v2 folder after compilation.

Copy all libboost*.a files to darkmod_src/macosx/boost/lib/.

I have a bugfix for the team

In case you figured out a problem in the TDM game code and you maybe even have a fix available, please drop by at our forums to tell the coding staff. Your fix might be incorporated in the main development branch.

Additional Info about the TDM Code

The Dark Mod codebase is quite large in the meantime and we have reorganised and refactored/replaced a number of things. There are a few things which haven't changed too much (like the animation code), but most gameplay code has been altered to fit TDM's needs.

Additionally, the TDM code relies on a few static libraries which are not required in the vanilla D3 code, see below.

Boost Libraries

TDM's code is using boost libraries. Most boost libraries we're using are header-only (i.e. they work without special linking), with the exception of filesystem, system, threads, program_options etc. The latter ones require a static library to be built for your OS and linked into the game code. For Windows the TDM source package you downloaded already contains the correct binaries for VC++ 2005 (7-zipped), VC++ 2008 and VC++ 2010 in both release and debug flavours. They can be found in the win32\lib folder.


For the FM installation code, we made use of the minizip/zlib sources. For Windows and Linux the package already comes with the correct static .lib and .a files, so this should work out of the box. In case you need to compile these libraries from scratch (e.g. for a newer compiler or a different OS) there is a .vcproj file available in win32\ziploader (Windows) or a sconscript in sys/scons/Sconscript.ziploader. Use these to compile a new static library and make sure the library is referenced by the d3game project.


Our lightgem code makes use of some image processing routines, which are contained in the open source DevIL package. The correct static library is already contained in the source package you downloaded, hence it should work right out of the box. In case you need to compile that library from scratch (applies to Windows only, Linux users will just need to download the correct package from their repositories), there are the DevIL sources in win32/devil, including a vcproj file, which you can use as basis.


The Dark Mod comes with a custom launching app named tdmlauncher which makes mission installation/uninstallation easier for players. The source code for the tdmlauncher is contained in the source package linked above, head to the folder dmlauncher/ where you'll find a Visual Studio solution file as well as a sconscript.tdmlauncher. TDMLauncher is making use of boost::filesystem, that's why there is a separate lib/ folder in there as well (for Linux only). See above for info about the boost libraries.

How to compile the boost static libraries in Windows

See also the main article: Compile the static Boost Libraries in Windows

Any VC++ compiler version other than VC++ 2008 or VC++ 2010 will require a recompile of the boost static libraries which The Dark Mod links against. At the time of writing, TDM is using the following boost libraries:

  • boost.filesystem
  • boost.system
  • boost.thread
  • boost.date_time
  • boost.program_options (for the updater/packager)

Now take the *.lib files and copy them into your win32/lib folder in your source directory and the linking should succeed.

Note for VC++ 2005 users: the boost libraries needed to link the game library are shipped in the darkmod source package in compressed format in win32/libs/libboost_binaries_vc++2005.7z. Unpack that archive if you need them.