Archive for February 3rd, 2010

Cross Compiling the Engine

Posted in Announcements on February 3rd, 2010 by Clonk-Karl – 2 Comments

In case you want to cross compile the OpenClonk engine from Linux, this is how I made it work:

First, install the mingw32 cross compiler for your distribution. On Debian the package is called mingw32. Then, fetch the required dependencies. You can get libpng, jpeg, zlib, freetype and openssl from gnuwin32. Fetch the developer packages and unpack all to a deps/ subdirectory. glew binaries can be found on its hompage. I put these into a separate glew/ directory but it’s probably also fine to throw the files together with the others into deps/. fmod can be fetched from Again, I put it into a separate fmod/ directory.

Now comes the only somewhat tricky part: The d3dx library. MinGW has a library file for it, called libd3dx9d.a, but there are no header files. However, Wine ships them (in /usr/include/wine/windows/d3dx9*.h on my system). So copy all of them into d3dx9/include/ (or deps/include/ FWIW). Not all symbols used by OpenClonk are declared in Wine’s header files though, so I added the remaining ones required. Here is the resulting patch. There is one more problem though: MinGW’s libd3dx9d.a does not export the symbol D3DXCompileShader. I therefore used d3dx9.lib from the official DirectX SDK and put it into d3dx9/lib/. If you don’t have it already it’s quite annoying to obtain though: You have to download a multi-100MB installer just for that single library file. I think it should be possible however to create a working libd3dx9.a using Wine’s .def file, but I haven’t tried this.

OK, so once this is done we have all dependencies together. What remains to be done is to create a so-called toolchain file for cmake to tell it that we are not going to target the platform on which we are building. For that purpose, create a new file called toolchain-mingw32.cmake (or different, it does not matter) and add this content:

# the name of the target operating system
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc /home/ck/deps /home/ck/glew/glew-1.5.2 /home/ck/d3dx9 /home/ck/fmod/fmodapi375win/api)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment

Remember to adapt the paths to the dependency files as necessary. One final thing to do, if you have used separate directories for glew, fmod and d3dx9 is to add Symlinks to deps:

ln -s glew/glew-1.5.2/include/GL deps/include/GL
ln -s fmod/fmodapi375win/api/inc/*.h deps/include
ln -s d3dx9/include/*.h deps/include

I think this is only required because OpenClonk’s CMake script does not add the include paths of these libraries to the Compiler Flags (which it probably is supposed to do). Finally run

cmake -DCMAKE_TOOLCHAIN_FILE=~/toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=~/mingw-install

and have fun watching how the Code is compiled.