Compiling on Windows using Microsoft Visual C++ 2012
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.
I'm assuming that you have Microsoft Visual Studio installed and running.
- Microsoft® Windows® SDK
- openttd-useful-X.X-win.zip -> Source files needed to compile.
- DMusic_for_OpenTTD.zip -> Old DirectMusic includes.
- TortoiseSVN A Windows program for get and update code from SVN repositories.
Step 1 - Preparing the files
1.1 Create your main
Work folder (ie
1.2 Create a subfolder called
trunk inside the previously created folder.
1.4 Extract the previously downloaded file
openttd-useful-X.X-win.zip inside our
Work folder and a folder called
OpenTTD essentials will be created.
1.5 Extract the previously downloaded file
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
2.4 A popup will ask you to update the compiler settings, click
2.5 Go to
Compile -> Configuration Administrator and select
2.6 Right click on the
openttd project in
Solution Explorer and select
Configuration: Release at the top of the Property window.
2.8 Navigate to
Configuration Properties -> VC++ Directories.
Include files folder and add
(WorkFolder)\OpenTTD essentials\shared\include; to the list.
DON'T forget the final semicolon(;) it's important.
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
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: https://www.openttd.org/en/download-openttd-useful/6.0.
For more details, see the discussion here: https://www.tt-forums.net/viewtopic.php?t=73769.
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 'openttd_vs100' in
Solution Explorer, make right click with the mouse over it and click on
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)
C/C++ -> Preprocessor.
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)
Advanced property page.
Choose "No" under "Image Has Safe Exception Handlers".
More info: 
Fix Warning C4005: "'FACILITY_DIRECTMUSIC' : macro redefinition"
openttd tree in
Solution Explorer, open
External Dependencies and select
Change this at the start of the file (usually near line 12):
#define FACILITY_DIRECTMUSIC 0x878 /* Shared with DirectSound */
#ifndef FACILITY_DIRECTMUSIC #define FACILITY_DIRECTMUSIC 0x878 /* Shared with DirectSound */ #endif