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-brunel 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.
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
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 repository 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
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/
Now you can optionally move the enviroment to a system directory
sudo mv mxe /opt/mxe
# Change to yours. For example, for MXE static would be x86_64-w64-mingw32.static CROSS=x86_64-w64-mingw32 # Default if installed via distribution. Change to yours. MINGW_PATH=/usr/$CROSS # 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" PATH=/usr/$CROSS/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
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:
CC=$(CROSS)gcc CXX=$(CROSS)g++ LD=$(CROSS)ld WINDRES=$(CROSS)windres PKG_CONFIG=$(CROSS)pkg-config 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):
And Simutrans will compile a windows executable!
LDFLAGS += -fstack-protector
This is known to happen on Arch Linux, provided you installed dependencies from the AUR (10-2020).