Compiling on Windows using MSYS2
This page contains guidelines for compiling OpenTTD for Win32 with MSYS2, or MinGW.
- Download and run the relevant MSYS2 installer from https://www.msys2.org/ . You'll likely want the x86_64 version, unless your computer is particularly old
- Please note that MinGW should be installed to a directory path that doesn't contain any spaces. This page has been tested with, and assumes, a directory path of C:\msys64. If you change this, adjust the rest of the commands as appropriate)
- Wait until every package has been downloaded and installation is finished.
Note that while the installer gives you the option of opening MSYS, this is not the program we will be using - MSYS2 comes with MinGW32 & MinGW64 variants.
For this tutorial we will be using the MinGW64 shell - usually
You can copy and paste into MinGW windows by using CTRL+INS (instead of CTRL+V)
Setting up MSYS2 (optional)
While the defaults for MSYS2 are perfectly fine for compiling OpenTTD, MSYS2 creates its own set of directories and you may want to merge a few of them into what you have already, e.g. your Unix home directory (
/home/<user>/) with your Windows user directory (
Go to your MSYS2 folder (found at C:\msys64) and open etc\fstab with a text editor (for example Notepad++) and add the following line at the end of the file:
MSYS2 uses the
pacman program to download libraries and for package management. There is also the
pacboy helper program for MinGW environments, such as the one we are using.
First step is to ensure the system is fully up to date. Run:
to update all system packages. It may ask you to exit the terminal window "without calling exit" - close the window and reopen it, then run the command again.
OpenTTD requires a couple of programs in the MSYS subsystem, and most others in the relevant MinGW subsystem.
You can install
make with the following command:
pacman -S git make
The following need to be installed in the relevant MinGW subsystem:
You can either type out the full name of mingw-w64-<arch>-<pkg> for each package, or use pacboy to manage them for you:
pacboy -S gcc:x pkg-config:x zlib:x lzo2:x xz:x libpng:x freetype:x
The ':x' on the end of each designates x86_64, or 64 bit, architecture. Swap it for ':i' if you want 32 bit, or remove it entirely to download the package for both architectures.
Getting the source code
Open the MinGW64 shell and run
git clone https://github.com/OpenTTD/OpenTTD
The OpenTTD source code is now in the
OpenTTD subdirectory of your MSYS home folder (C:\msys64\home\<user>\OpenTTD).
Start MinGW64, and run the following:
cd ~/OpenTTD # '~' means your home folder ./configure make
When OpenTTD has finished compiling an 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 (C:\msys64\home\<your Windows user name>\OpenTTD in this example). Then, in the MINGW64 shell:
cd ~/OpenTTD patch -p1 < <patch name>
-p0 for Subversion style patches,
-p1 for all others (it's probably a good idea to try
-p1 first if you don't know). Explanation of the difference: FAQ development#How to apply a patch