Latest Posts

BuildingWidelandsUnderWindowsNew

How to build Widelands with MSys2/MinGW64 on Windows

This is currently a work in progress!

Building with MSys2 only

Download and install MSys2

  1. Download MSYS2 from MSYS2.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. Running pacman -Syuu repeatedly and following the instructions on screen should do it.

Install the toolchain and the dependencies

  1. 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.
  2. 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.
  3. Install Bazaar (our version control system): pacman -S bzr
  4. If you want to use GLEW instead of glbinding: pacman -S mingw-w64-x86_64-glew / pacman -S mingw-w64-i686-glew
  5. You might need to downgrade Boost

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

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

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 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.66.0-2-any.pkg.tar.xz for 64bit builds.

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.

Building with Nuwen's MinGW64 distro

Download files

Nuwen's MinGW64 distro

Download the main distro from http://nuwen.net/mingw.html and the MSYS2 installer:

CMake and Ninja

  • Download Ninja. Extract simply to C:\MinGW\bin.
  • Download CMAKE

Widelands source code

SDL2 source packages

Additional libraries

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!
  • 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
  • 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)

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

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 No problems
    • libjpeg 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 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 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 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

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 page.
  • For building with GLEW, add the CMake option -DOPTION_USE_GLBINDING=OFF
  • Just call "ninja" to build now