Compiling on Windows using Microsoft Visual C++ 2012

From OpenTTD
Jump to: navigation, search

A step by step guide for compile successfully OpenTTD in Visual Studio 2012. Note the 2008/2010 version of this document contains more information (such as creating a bundle) and is more verbose, hence if you get stuck it is recommended to look at that document as well.


Before Start

I'm assuming that you have Microsoft Visual Studio installed and running.

Required software


This guide has been tested on Windows 8 64 bits, it should work on other Windows versions too, if you find any additional errors please let us know in the forum.

Step 1 - Preparing the files

1.1 Create your main Work folder (ie C:\OpenTTD)

1.2 Create a subfolder called trunk inside the previously created folder.

1.3 Select trunk folder and make a check-out with TortoiseSVN using svn:// as URL (if you need help see svn checkout)

1.4 Extract the previously downloaded file inside our Work folder and a folder called OpenTTD essentials will be created.

1.5 Extract the previously downloaded file inside OpenTTD essentials folder.

Step 2 - Configure Visual Studio

2.1 If you have Visual Studio running, close it first, then install Microsoft Windows SDK.

2.2 Open Microsoft Visual Studio and go to File -> Open Project.

2.3 Select the file (WorkFolder)\trunk\projects\openttd_vs100.sln.

2.4 A popup will ask you to update the compiler settings, click Update button.

2.5 Go to Compile -> Configuration Administrator and select Configuration: Release.

2.6 Right click on the openttd project in Solution Explorer and select Properties.

2.7 Select Configuration: Release at the top of the Property window.


You can leave both settings as default in Debug if you want but you will need to repeat these steps when you change it later to Release.

2.8 Navigate to Configuration Properties -> VC++ Directories.

2.9 Select Include files folder and add (WorkFolder)\OpenTTD essentials\shared\include; to the list. DON'T forget the final semicolon(;) it's important.

2.10 Select Library files folder and add (WorkFolder)\OpenTTD essentials\win32\library; to the list. Again DON'T forget the final semicolon(;) it's important, change win32 to win64 if you want to compile a x64 build.

You can try now to build the solution.

Your final file will be in (WorkFolder)\trunk\objs\Win32\Release\openttd.exe

Error troubleshooting

Fix Error LNK2001 unresolved external symbol ___iob_func openttd C:\OpenTTD\trunk\projects\libpng.lib(pngerror.obj)

You're probably using an outdated version of openttd-useful. You can find version 6.0 here:

For more details, see the discussion here:

Fix for Error C1083: Cannot open (include file/source file) 'X' No such file or directory

This usually happens when you try to compile only the openttd project, you must compile entire solution because some needed files are created by scripts "on the fly"

Solution: Select Solution 'openttd_vs100' in Solution Explorer, make right click with the mouse over it and click on Compile Solution.

Fix for Error C1189: "The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro[...]"

Open the project's Property Pages dialog box. (See step 2.6)

Navigate to C/C++ -> Preprocessor.

Select Preprocessor Definitions and add


to the list. DON'T forget the final ; it's important

Fix Error LNK2026: "Module unsafe for SAFESEH image[...]"

Open the project's Property Pages dialog box. (See step 2.6)

Click the Linker folder.

Click the Advanced property page.

Choose "No" under "Image Has Safe Exception Handlers".

More info: [1]

Fix Warning C4005: "'FACILITY_DIRECTMUSIC' : macro redefinition"

Open openttd tree in Solution Explorer, open External Dependencies and select dmerror.h

Change this at the start of the file (usually near line 12):

#define FACILITY_DIRECTMUSIC      0x878       /* Shared with DirectSound */


	#define FACILITY_DIRECTMUSIC      0x878       /* Shared with DirectSound */

Personal tools