Latest Posts

Changes in BuildingWidelandsUnderWindowsNew

Editor Comment

Added: CMake error connected to wrong boost version


Revision Differences of Revision 53

# How to build Widelands with MSys2/MinGW64 on Windows ¶

This is currently a work in progress! ¶

[TOC] ¶

# Building with MSys2 only ¶

## Download and install MSys2 ¶

1. **Download MSYS2** from [MSYS2.io](https://msys2.github.io), eiher the 64 bit or the 32 bit version, depending on which type of build you want to create ¶
2. Depending on your version, **install** to `C:\msys64` or `C:\msys32` ¶
3. **Run** `C:\msys64\mingw64.exe` or `C:\msys32\mingw32.exe` ¶
4. Follow the [update steps](https://github.com/msys2/msys2/wiki/MSYS2-installation#iii-updating-packages). Running `pacman -Syuu` repeatedly and following the instructions on screen should do it. ¶

## Install the toolchain and the dependencies ¶

5. Install the mingw64 **toolchain** (or mingw32 toolchain) using `pacman -S mingw-w64-x86_64-toolchain` for 64bit builds, `pacman -S mingw-w64-i686-toolchain` for 32bit builds. Select to install all options. ¶
6. Install **CMake** and all **dependencies** : `pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-boost mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-glbinding` for 64bit builds, `pacman -S mingw-w64-i686-cmake mingw-w64-i686-ninja mingw-w64-i686-boost mingw-w64-i686-SDL2_ttf mingw-w64-i686-SDL2_mixer mingw-w64-i686-SDL2_image mingw-w64-i686-glbinding` for 32bit builds. ¶
7. Install **Bazaar** (our version control system): `pacman -S bzr` ¶
8. If you want to use **GLEW** instead of glbinding: `pacman -S mingw-w64-x86_64-glew` / `pacman -S mingw-w64-i686-glew` ¶
9. You might need to [downgrade Boost](https://wl.widelands.org/wiki/BuildingWidelandsUnderWindowsNew/#cmake-cant-find-the-boost-package) ¶


## Get the Widelands sources ¶

~~~~ ¶
mkdir widelands ¶
cd widelands ¶
bzr init-repo . ¶
bzr branch lp:widelands trunk ¶
bzr branch trunk <my_own_branch_to_work_on> ¶
cd <my_own_branch_to_work_on> ¶
~~~~ ¶

[How to use bazaar](https://wl.widelands.org/wiki/BzrPrimer/) ¶

## Configure the build ¶

~~~~ ¶
mkdir build ¶
cd build ¶
~~~~ ¶

For 64bit builds: ¶
~~~~ ¶
cmake -G "Ninja" -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe -DCMAKE_BUILD_TYPE=Release -DOPTION_USE_GLBINDING=OFF -DOPTION_BUILD_WEBSITE_TOOLS=OFF -DOPTION_ASAN=OFF .. ¶
~~~~ ¶

For 32bit builds: ¶
~~~~ ¶
cmake -G "Ninja" -DCMAKE_C_COMPILER=C:/msys32/mingw32/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys32/mingw32/bin/g++.exe -DCMAKE_BUILD_TYPE=Release -DOPTION_USE_GLBINDING=OFF -DOPTION_BUILD_WEBSITE_TOOLS=OFF -DOPTION_ASAN=OFF .. ¶
~~~~ ¶

these CMAKE options define the following values in their order of appearance: ¶
- use "ninja" instead of "MAKE" ¶
- the c and c++ compiler are defined to be gcc and g++ (Don't change this) ¶
- the build type is "Release" (switch to "Debug" for a debug build ) ¶
- GLEW is used instead of GLbinding (switch to ON for a GLbinding build) ¶
- website tools are not build (saves time) ¶
- AddressSanitizer (ASAN) is not used ¶

to save time you could switch off Generation of translations with -DOPTION_BUILD_TRANSLATIONS=OFF ¶

[More CMake options](https://wl.widelands.org/wiki/BuildingWidelands/#cmake-options) ¶

## Run the build ¶

~~~~ ¶
ninja ¶
~~~~ ¶

## Toubleshooting ¶

### The cmake, bzr etc. commands can't be found ¶

You will need to add the tool binaries to the system path. You can do so by calling: ¶

`export PATH=${PATH}:/c/msys64/mingw64/bin` for 64bit builds, `export PATH=${PATH}:/c/msys64/mingw32/bin` for 32bit builds. ¶

You'll need to do that on every restart of Msys2. ¶

### CMake can't find the Boost package ¶

Sometimes, the Boost packages get updated before CMake findpackage can keep up with them. If that fail, you will need to downgrade Boost. Download the boost 1.66 package and its signature file from [The MinGW Repository](http://repo.msys2.org/mingw) to `C:\msys42\home\<username>`. Call `pacman -U <tar_xz_filename>`. Alernatively, downgrade directly off the repo, e.g. `pacman -U http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-boost-1.68.0-2-any.pkg.tar.xz` for 64bit builds. ¶

###
CMake error messages ¶

It can happen that running `cmake` results in errors like the following. ¶

~~~~ ¶
CMake Error at cmake/WlFunctions.cmake:78 (wl_include_system_directories): ¶
wl_include_system_directories Function invoked with incorrect arguments for ¶
function named: wl_include_system_directories ¶
Call Stack (most recent call first): ¶
cmake/WlFunctions.cmake:176 (_common_compile_tasks) ¶
src/CMakeLists.txt:26 (wl_library) ¶
~~~~ ¶

Even if the message doesn't mention it ths can be a problem related to Boost. Downgrading Boost can be one possible solution. Version 1.68 should be fine. ¶

###
Error messages when linking ICU ¶

~~~~ ¶
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/graphic/text/libgraphic_text.a(bidi.cc.obj):bidi.cc:(.text+0x6c): undefined reference to `icu_61::UnicodeString::UnicodeString(char const*, char const*)' ¶
~~~~ ¶

When you get these, you probably have an ICU version sitting in `C:/Windows/System32/` that is being found instead of the MSys2 copy. Did you start MSys2 using `msys2_shell.cmd`? Try running `mingw64.exe` / `mingw32.exe` instead. ¶

### Speeding up the file system ¶

You can speed up the file system a little bit by doing the following: ¶

* Go to the control panel and search for "Indexing Options". Maje sure that the MSys folder and your source code is not included ¶
* Right-click on the MSys folder and choose "Properties" -> "General" -> "Advanced" and switch off the indexing of file contents. Do the same for your source code directory. ¶

You can still search the contents of your files afterwards from the MSys shell, using the `grep` command. ¶

### Still having problems? ¶

Please post any issues to the [relevant forum thread](https://wl.widelands.org/forum/topic/4316/). ¶

# Building with Nuwen's MinGW64 distro ¶

## Download files ¶
### Nuwen's MinGW64 distro ¶

Download the main distro from [http://nuwen.net/mingw.html](http://nuwen.net/mingw.html) and the MSYS2 installer: ¶

* [mingw-13.4.exe](http://nuwen.net/files/mingw/mingw-13.4.exe) ¶
* [MSYS2](http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20150916.exe) from [MSYS2.io](https://msys2.github.io) ¶

### CMake and Ninja ¶

* Download [Ninja](https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip). Extract simply to `C:\MinGW\bin`. ¶
* Download [CMAKE](https://cmake.org/files/v3.4/cmake-3.4.1-win32-x86.zip) ¶

### Widelands source code ¶

* This is described on [[ BzrPrimer ]] ¶

### SDL2 source packages ¶
* [SDL2](https://www.libsdl.org/release/SDL2-2.0.3.zip) ¶
* [SDL2_net](https://www.libsdl.org/projects/SDL_net/) (For Build 19 and older) ¶
* [SDL2_mixer](http://www.libsdl.org/projects/SDL_mixer/) ¶
* [SDL2_image](https://www.libsdl.org/projects/SDL_image/) ¶
* [SDL2_ttf](https://www.libsdl.org/projects/SDL_ttf/) ¶

### Additional libraries ¶
* [gzip](http://ftp.gnu.org/gnu/gzip/gzip-1.6.tar.gz) ¶
* [libiconv](http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz) ¶
* [gettext](http://ftp.gnu.org/gnu/gettext/gettext-0.19.6.tar.gz) ¶
* [freetype](http://download.savannah.gnu.org/releases/freetype/freetype-2.6.2.tar.gz) ¶
* [ICU](http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.zip) ¶
* [GLEW](http://glew.sourceforge.net/) or glbinding ¶

## Set up and start the environment ¶

* Use the self-extracting installer of Nuwen's and extract the distro to `C:\MinGW` ¶
* Install MSYS2 to `c:\msys2` and follow their [update steps](https://github.com/msys2/msys2/wiki/MSYS2-installation#iii-updating-packages)! ¶
* Open the distro window with `C:\MinGW\open_distro_window.bat` ¶
* In this shell change the directory with `cd c:\msys2` and call `msys2_shell.bat` or `msys2_shell.cmd` to start MSYS2, depending on your version of MSYS2. ¶
* You are now in a linux like shell, so the command syntax is a bit different than normal windows commands ¶
* Call `pacman -S diffutils` to make sure that the "cmp" and "diff" commands are available. The libraries will need those to configure themselves - you will probably get errors like "./configure: line 5988: cmp: command not found" otherwise. ¶
* Call `gcc --version`. If the reply is `bash: gcc: command not found`, you will need to add it to the path with `export PATH=${PATH}:/c/MinGW/bin`. Do this every time you start MSYS2. ¶


## Build all libraries ¶


* Extract all source packages to `c:\msys2\home\<username>\` ¶
* Build each package with `./configure --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/c/MinGW && make install` ¶
* Gzip1.6 does not compile without these [two patches](https://gist.github.com/TinoM/5692d59573269e6d8018) ¶
* Download the patch files, save them in the gzip source folder and patch with ¶
* patch -d . -p1 < gzip_mingw64.patch ¶
* patch -d . -p1 < gzip_mingw64_2.patch ¶
* Libiconv and freetype have circular dependencies, so you should compile libiconv, then freetype and then libiconv again (run `make distclean` and `./configure`) ¶
* libiconv: If you get a warning `remember to run 'libtool --finish /c/MinGW/lib'`, just run that command when the install has finished. If you don't have libtool, `pacman -S libtool` will fix that for you. ¶

## Troubleshooting ¶

### no acceptable C compiler found in $PATH ¶

* You will need to execute `export PATH=${PATH}:/c/MinGW/bin` within MSYS2. You can run `gcc --version` to check that it's there ¶

### libiconv ¶
* If compiling fails due to problems with the `INSTALLDIR` macro, track down the files and replace the macro with the hard-coded path, e.g. replace all instances of `const char *orig_installdir = INSTALLDIR;` with `const char *orig_installdir = "/c/MinGW";` (solution from [Chinese site](https://www.cnblogs.com/paktc/p/5997500.html)) ¶

### icu ¶
* icu4c-61_1 will not compile on MinGW, use icu4c-56_1 as linked above. ¶

### SDL2_mixer ¶
* If you get lots of warnings like "undefined reference to `oggpack_write'" etc, you'll need to get and compile [libvorbis](https://xiph.org/downloads/) ¶

### SDL2_image ¶
* I kept getting an error "libobj name `IMG.Tpo -c -o IMG.lo IMG.lo' may not contain shell special characters." that would not go away. They provide ready-made development packages though (SDL2_image-devel-2.0.3-mingw.tar.gz (MinGW 32/64-bit)), so try grabbing one of those. I tried fixing the error by compiling the depencies. Ran into some trouble with the dependencies too and am documenting it here, just in case it will come in useful: ¶
* [libtiff](https://gitlab.com/libtiff/libtiff) No problems ¶
* [libjpeg](http://libjpeg.sourceforge.net/) `cannot create regular file '/c/MinGW/man/man1/cjpeg.1': No such file or directory`. Simply create the `C:\MinGW\man\man1` folder and run `make install` again ¶
* [libpng](http://libpng.org/pub/png/libpng.html) Get a tar distribution, or there will be no configure available. `pnglibconf.h:205:54: error: expected identifier or '(' before '-' token` - Open pnglibconf.h and delete the extra line breaks, so that every #define statement is in a single line ¶
* [zlib](https://www.zlib.net/) Does not use autotools, so the configure command is `./configure --static --64 --prefix=/c/MinGW`. Then `make install` as usual ¶

### Gettext ¶
* Install perl `pacman -S perl` ¶
* Compiler complains about `LOCALE_ALIAS_PATH` and `LOCALEDIR`: Replace `LOCALE_ALIAS_PATH` and `LOCALEDIR` with `"/c/MinGW/share/locale` in: ¶
* gettext-runtime/intl/dcigettext.c ¶
* gettext-runtime/intl/localealias.c ¶
* gettext-runtime/intl/os2compat.c ¶
* gettext-runtime/intl/os2compat.h ¶
* Compiler complains about `INSTALLDIR`: In `gettext-runtime/intl/relocatable.c`, delete all instances of `&& defined INSTALLDIR` and then replace `INSTALLDIR` with `"/c/MinGW/lib"` ¶
* "undefined reference to \`__imp_pthread_rwlock_unlock'" - Get the [precompiled pthreads binary](https://sourceforge.net/p/mingw-w64/wiki2/Compile%20pthreads/) and dump it into `C:\MinGW` ¶
* `aclocal-1.15: command not found`: Install autotools `pacman -S automake m4 autoconf` ¶
* Problems with an `sed` command: ¶
* Call `cd gettext-runtime` and compile gettext from there ¶
* The error is coming from `gettext-tools` - you can grab those from MSYS2 by copying `msgfmt.exe` and `msgmerge.exe` from `C:\msys64\mingw64\bin` to `C:\MinGW\bin` - that will be enough to make CMake happy. If you want to build `.pot` catalogs, you will also need `xgettext.exe`. ¶
* The above error looks like this: ¶
~~~~ ¶
} > math.h-t && \ ¶
mv math.h-t math.h ¶
/usr/bin/sh: -c: line 214: syntax error: unexpected end of file ¶
make[4]: *** [Makefile:4294: math.h] Error 1 ¶
~~~~ ¶

* In case you're still having trouble, you can try the [MSYS2 patches](I have found a series of patches: https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-gettext) ¶

## Build Widelands ¶

We will build ninja in the normal distro window and not in the MSYS shell: ¶

* Open the distro window with `C:\MinGW\open_distro_window.bat` ¶
* Switch to the directory you'll want to build widelands in, e.g. `C:\wl_build` ¶
* run CMAKE `cmake -G Ninja -DCMAKE_PREFIX_PATH=C:\Mingw c:\bzr\widelands\trunk`. Important CMake options are documented on the [BuildingWidelands](https://wl.widelands.org/wiki/Building%20Widelands/#cmake-options) page. ¶
* For building with GLEW, add the CMake option `-DOPTION_USE_GLBINDING=OFF` ¶
* Just call "ninja" to build now