Skip to content

Cross compile using MXE

zwostein edited this page Aug 27, 2013 · 4 revisions

Cross compile using MXE

This is a quick reference on how to compile a Windows executable on a Linux machine using the MXE toolchain

Install the toolchain

Download MXE from http://mxe.cc/#tutorial and install the cross compiler including all dependencies:

make gcc qt openal glew vorbis ogg

This will take a while...

Get the source

$ git clone https://github.com/splatterlinge/Splatterlinge.git
$ cd Splatterlinge

Setup CMake for cross-compiling

MXE provides a toolchain file for CMake. Unfortunately, running CMake with the toolchain file only won't suffice and you'll probably end up with linker errors. To make the linker work, you'll have to add additional libraries and some defines:

cmake -DCMAKE_CXX_STANDARD_LIBRARIES:STRING="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -llzma -llcms -lvorbis -logg" \
-DCMAKE_C_FLAGS:STRING="-DAL_LIBTYPE_STATIC -DGLEW_STATIC" \
-DCMAKE_CXX_FLAGS:STRING="-DAL_LIBTYPE_STATIC -DGLEW_STATIC" \
-DCMAKE_TOOLCHAIN_FILE=###PATH_TO_MXE###/usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake .

Don't forget to replace ###PATH_TO_MXE### with your actual directory containing MXE.

Compile

$ make

If you installed "Wine", you can check if the executable is ok on your Linux machine, too:

$ wine ./bin/Ununoctium.exe