Compiling on Windows using MinGW
This guide is about MinGW/MSYS1, which is very old and not maintained any longer. It's much better, and easier, to use Compiling on Windows using MSYS2
This page contains guidelines for compiling OpenTTD for Win32 with MinGW.
List of packages
This tutorial has been tested with the following versions of the required packages:
- OpenTTD 1.2.x or trunk.
- Subversion 1.7.6
Installing MinGW and MSYS
- Download and run mingw-get-inst (the download link can be found in the previous section).
- Select "Use pre-packaged repository catalogues".
- Review and accept the License agreement.
- Please note that MinGW should be installed to a directory path that doesn't contain any spaces. This method has been tested with a directory path of C:\MinGW.
- Select C++ Compiler and MSYS Basic System as optional components.
- Wait until every package has been downloaded and installation is finished.
Setting up MSYS
Go to your MSYS folder (found at <MinGW installation folder>\msys\1.0, C:\MinGW\msys\1.0 in this example), open etc\fstab with a text editor (for example Notepad) and add the following line at the end of the file:
On Windows Vista and newer, you'll need additional steps to make MSYS fully work if User Account Control is enabled (it is by default). Go to your MSYS folder (C:\MinGW\msys\1.0 here), open msys.bat with a text editor (right-click -> Open With -> Notepad or equivalents) and add the following line after
And if your MSYS installation drive is not the disk Windows is installed on, add one more line:
After saving the file, right click on msys.bat and choose "Run as Administrator". You will need to do this every time you run MSYS. After that, programs requiring admin rights (such as
patch) will work.
Testing MinGW/MSYS installation
- Open the MinGW shell (MSYS) by running msys.bat.
- Run the following commands:
make -v gcc -v
- They should output something. Check if something goes wrong.
If you get the error
gcc: command not found
browse your MinGW directory to msys\1.0\postinstall and run pi.bat
Compilation and installation of the required packages
For additional information about the libraries, check part 7.1) of OpenTTD Readme. To compile and install these packages and avoid the error '
wget: command not found', first you need to install the following commands:
(To compile on Windows 7, the service "application experience" must be activated and running)
You can copy and paste into MingW windows by using CTRL+INS istead of CTRL+V
mingw-get install msys-wget mingw-get install msys-unzip mingw-get install msys-patch
If you get following error:
configure: error: cannot run C compiled programs.
, one of the reasons could be your anti-virus, that silently deletes a.exe binary files. Try to temporarily disable anti-virus software and compile again.
wget http://sourceforge.net/projects/win32svn/files/1.7.6/apache22/svn-win32-1.7.6.zip/download --no-check-certificate unzip svn-win32-1.7.6.zip cd svn-win32-1.7.6 mv bin/* /usr/local/bin/ cd ..
wget http://zlib.net/zlib-1.2.11.tar.gz tar xvfz zlib-1.2.11.tar.gz cd zlib-1.2.11 make -f win32/Makefile.gcc BINARY_PATH=/bin INCLUDE_PATH=/usr/local/include LIBRARY_PATH=/usr/local/lib install cd ..
If your not able to compile it with the command line commands above you could try installing it with the "MinGW Installation Manager", its called: mingw32-libz. If wget is unable to find the server, the maintainers have probably moved up to another rev. Go to http://zlib.net to see the new rev and then simply change all instances of 1.2.11 to the new rev (1.2.[rr]).
wget http://sourceforge.net/projects/libpng/files/libpng15/older-releases/1.5.16/libpng-1.5.16.tar.xz/download --no-check-certificate tar xvfJ libpng-1.5.16.tar.xz cd libpng-1.5.16 mv INSTALL INSTALL.txt ./configure make install cd ..
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz tar xvfz lzo-2.06.tar.gz cd lzo-2.06 ./configure --enable-static make install cd ..
wget http://sourceforge.net/projects/freetype/files/freetype2/2.4.10/freetype-2.4.10.tar.gz --no-check-certificate tar zxvf freetype-2.4.10.tar.gz cd freetype-2.4.10 ./configure --enable-static make install cd ..
Liblzma (which is a part of xz) is required for compiling OpenTTD since r21044. It also needs pkg-config and its dependencies. In MSYS:
wget http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip unzip gettext-runtime_0.18.1.1-2_win32.zip -d /usr/local wget http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.26/glib_2.26.0-2_win32.zip unzip glib_2.26.0-2_win32.zip -d /usr/local wget http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip unzip pkg-config_0.23-3_win32.zip -d /usr/local wget http://tukaani.org/xz/xz-5.0.4.tar.gz --no-check-certificate tar xvfz xz-5.0.4.tar.gz cd xz-5.0.4 ./configure --enable-static --disable-threads make install cd ..
libicu is an optional library used for handling of right-to-left scripts (e.g. Arabic and Persian) and the natural sorting of lists. It can take a long time to compile, so you can safely omit this step if you don't require libicu.
wget http://download.icu-project.org/files/icu4c/4.8/icu4c-4_8-src.zip unzip icu4c-4_8-src.zip cd icu wget http://devs.openttd.org/~terkhen/libicu/libicu_4_8_mingw32.diff patch -p1 -i libicu_4_8_mingw32.diff wget http://devs.openttd.org/~terkhen/libicu/libicu_reduce_icudata_size.diff patch -p1 -i libicu_reduce_icudata_size.diff cd source ./configure --enable-static --disable-shared --disable-strict --disable-threads make install cd ../..
Getting the source code
Open the MSYS shell and run
cd && git clone https://github.com/OpenTTD/OpenTTD.git
The OpenTTD source code is now in the
trunk subdirectory of your MSYS home folder (<MinGW installation folder>\MSYS\1.0\home\<your Windows user name>).
- Start MSYS.
cd ~/<path_to_source> ./configure make(note that ~ means your MSYS home folder)
- The compiling is complete when the openttd.exe file is made. It will be copied to the
- To test your compilation you can run (from the same folder in which you compiled OpenTTD):
./bin/openttdDon't forget to install a base graphics set before this step if you don't have one (the simplest solution is to install OpenGFX)
- If you want to generate a installation bundle you can use:
make bundleAfter this command is done you will find a complete OpenTTD ready for distribution in the ~/<path_to_source>/bundle folder.
Patching the source code
Place the patch you want to apply into the directory the OpenTTD source code is located in (<MinGW installation folder>\MSYS\1.0\home\<your Windows user name>\trunk in this example). Then, in the MSYS shell:
cd ~/trunk patch -p1/p0 < <patch name>
Use p0 for Subversion style patches, p1 for all others (it's probably a good idea to try p1 first). Explanation of the difference: FAQ development#How to apply a patch