Cross-Compiling Simutrans

After successfully compiling Simutrans, you may be tempted to set up a Cross-Compilation Enviroment to build Simutrans for Windows from your Linux machine. Cross-compilation of Simutrans is indeed posible and made nightly on build servers, like the bridgewater-brunellink-external server that builds Simutrans-Extended. Depending on your system, setting up the enviroment is different, but in the end, all of then will be using mingw64, a cross-compilation platform, so steps for cross-compiling are the same after the set up.

Setting up the enviromentlink

For installing mingw64 on a GNU/Linux machine, you generally have two options: install from your distribution repositories or install the MXE enviroment. The first option can be more difficult depending on your distribution, but will integrate better. The second option works in any distribution and it is always easy to setup, but linking dynamically will generate an enormous executable (30MB vs the usual 10MB executable), because MXE is set up in such away that all libraries are either dinamically linked or statically linked.

Installing mingw64 from your distributionlink

Installing mingw64 on Fedoralink

sudo dnf -y upgrade && sudo dnf -y install mingw32-nsis mingw64-pkg-config mingw64-gcc mingw64-gcc-c++ mingw64-SDL2-static mingw64-zlib-static mingw64-bzip2-static mingw64-libpng-static mingw64-winpthreads-static mingw64-freetype-static

Installing mingw64 on Arch Linuxlink

On official repositories you only have the basic toolchain.
sudo pacman -S mingw64

For dependencies, you can install them from the AUR (they are all there) which means that they will be compiled before. If you prefer to get the binaries instead, you can add the ownstuff repositorylink-external to your /etc/pacman.conf
yay -S mingw-w64-bzip2 mingw-w64-freetype2 mingw-w64-libpng mingw-w64-miniupnpc mingw-w64-pkg-config mingw-w64-sdl2 mingw-w64-zlib mingw-w64-zstd

Installing mingw64 from MXElink

First get the project from GitHub.
git clone https://github.com/mxe/mxe.git

cd into the directory and build the dependencies, setting MXE_TARGETS to “x86_64-w64-mingw32.static” or “x86_64-w64-mingw32.dynamic” depending on your needs.
make MXE_TARGETS='x86_64-w64-mingw32.static' bzip2 cc freetype libpng sdl2 zlib zstd

This will build all necessary dependencies. If you don’t want to compile them (it will take a while), you can also download binaries from https://pkg.mxe.cc/link-external

Now you can optionally move the enviroment to a system directory
sudo mv mxe /opt/mxe


Compiling miniupnpclink

You may have noticed that we have not compiled miniupnpc previously. This is due to miniupnpc currently shipping a broken lib, soy you have to build it yourself in your brand new enviroment. You can use the following shell script for that, which will install miniupnpc to your enviroment. You have to change accordingly the first three variables, everything else don’t need any modifications.
# Change to yours. For example, for MXE static would be x86_64-w64-mingw32.static
# Default if installed via distribution. Change to yours.
# Default if installed via distribution. Change to yours. For example, for MXE static would be "/path/to/mxe/usr/x86_64-w64-mingw32.static/usr/bin:$PATH"

rm -rf master.zip
wget https://github.com/miniupnp/miniupnp/archive/master.zip
unzip -o master.zip
cd miniupnp-master/miniupnpc
cat Makefile.mingw | sed 's|[ \t]wingenminiupnpcstrings.exe |'"$(printf '\t')"'./wingenminiupnpcstrings.exe |' >Makefile.mingw2
make -f Makefile.mingw DLLWRAP=$CROSS-dllwrap CC=$CROSS-gcc AR=$CROSS-ar
cp libminiupnpc.a $MINGW_PATH/lib
cp *.h $MINGW_PATH/lib
mkdir $MINGW_PATH/include/miniupnpc
cp *.h $MINGW_PATH/include/miniupnpc

cd ../..
rm -rf master.zip
rm -rf miniupnp-master

Compiling Simutranslink

First. add the mingw64 bin path to your path, if not already added:
export PATH=/path/to/mingw64/bin:$PATH

This will add the path for your current terminal session.

For compiling the game, we can set up the config.default file the same way we do for mingw on Windows, but will have to add some lines to config.default:
FREETYPE_CONFIG=$(CROSS)pkg-config freetype2
SDL2_CONFIG=$(CROSS)pkg-config sdl2

Those lines will make sure that we use the tools (gcc, g++, etc) from the cross-compiler enviroment, instead of the system tools. Now, we can finally type (adjusting CROSS value to your enviroment):
make CROSS=x86_64-w64-mingw32-

And Simutrans will compile a windows executable!

Known Issueslink

If in the linking phase you get some errors regarding freetype or other libraries with undefined references to functions like “__chk_fail”, you may need to add the following to your config.default:
LDFLAGS += -fstack-protector

This is known to happen on Arch Linux, provided you installed dependencies from the AUR (10-2020).
Rate this page:

Contributors to this page: Roboron3042 .
Page last modified on Tuesday October 13, 2020 11:53:57 GMT-0000 by Roboron3042.

Online Users

9 online users

Newest Forum Posts

No records to display