This page or section contains content that is no longer relevant for the current version of OpenTTD. Please keep it intact because it shows some of the history of this wiki as documentation.
This page is only valid up to version 1.8. Later versions require Visual C++ 2015 or newer.
If you "just" want to compile/apply a single patch, it's probably a better idea to follow this article, word for word.
This article gets you started on compiling OpenTTD using Microsoft Visual C++ 2008/2010. Note that, for the Express Editions, compiling for 64-bit systems requires extra steps.
Contents |
Required software
- Microsoft® Visual C++ 2008 Express Editions (current: Final) VS2008 does not appear to be available anymore. This link leads to VS2013 page. VS2010 can also be downloaded from links on the page.
- Microsoft® DirectX SDK - August 2007 or earlier (only needed for DirectX Music, otherwise can be skipped. More later on.)
- Microsoft windows 7 SP1 SDK for 64 bit compilation only
-
openttd-useful-X.X-win.zip Choose to download the Headers/libraries.
- openttd_useful.zip is a collection of files of varying age. For the latest zlib, libpng, liblzo2 and FreeType files you can browse their websites below.
- zlib
- GnuWin32 libpng
- GnuWin32 FreeType
- ICU4C
- liblzo2
-
openttd-useful-X.X-win.zip Choose to download the Headers/libraries.
...and of course the newest source from
svn://svn.openttd.org/trunk
. You need to have a SVN-client to download the source from the SVN server. Pick either of the following two. For SVN novices TortoiseSVN is highly recommended:
- Subversion command line version (current: 1.7)
- GUI TortoiseSVN (current: 1.8.8)
Installing
Microsoft® Visual C++ 2008 Express Editions
If you just need to compile OpenTTD it's enough if you don't select any options, keep the default options and wait for the installation to finish (for illustration click the image).
Extra install required for 64bit compilation
You will need to install the windows SDK in order to compile the 64bit version
The only options you need are Developer Tools -> Windows Headers and Libraries.
Microsoft® DirectX SDK
If you don't want/need music, you can skip DirectX SDK. Please read next chapter on that.
- Install the version August 2007
From the components screen remove the documentation and sample source code you'll save a lot of space. They're pretty useless if you just need to compile OpenTTD (see the image below). For those of you who don't want to download the whole DirectX SDK package with several hundred megabytes you can use this handy zip file containg only headers needed for successfull OpenTTD compilation. You don't need the included dxguid.lib file for compiling trunk.
You should not use a version newer then August 2007 as DirectMusic is no longer support as of the November 2007 release. If you install a newer version, you should follow the instructions of #microsoft-r-directx-sdk-earlier-than-august-2007
As August 2007 or earlier installer doesn't support Microsoft® Visual Studio 2008, you will have to set up the VC++ directories manually.
Go to
Tools -> Options
, then toProjects and Solutions -> VC++ Directories
. Add the following lines:
Include files:
- C:\Program Files\Microsoft DirectX SDK\Include
Library files:
- C:\Program Files\Microsoft DirectX SDK\Lib\x86
Note: Please update the paths as necessary.
Without Microsoft® DirectX SDK
Alternative: If you are willing to compile without support for MIDI music you will not be needing the DirectX SDK. To disable music, open the "openttd" project properties dialog and:
-
Navigate to
Configuration properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
and removeWIN32_ENABLE_DIRECTMUSIC_SUPPORT
preprocessor definition.
-
Navigate to
-
Navigate to
Configuration properties -> Linker -> Input -> Additional Dependencies
and removedxguid.lib
library. note: this may no longer be necessary
-
Navigate to
Preparing your system for 64bit compilation
- Note: these instructions for using a 64bit version of Windows. If you are using a 32bit version, the registry edit will be different
- Download this .REG file and import it to your registry (https://docs.google.com/open?id=0B22TZ_qFdiWQYV9DSDZCV0Iwd3M)
-
Open folder 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcpackages'
- rename / delete VCProjectEngine.Dll.Express.Config it gets replaced below
-
change the extention from .config to .Express.config for the following files
- AMD64.VCPlatform.Config
- VCProjectEngine.dll.Express
Copying from OpenTTD needed includes and libraries
-
Extract the openttd-useful.zip file and copy the content to some
<personal folder>
. -
In the guide below: Don't forget to replace
<personal folder>
with the folder where you extracted openttd-useful.zip.
-
Extract the openttd-useful.zip file and copy the content to some
Visual C++ Express 2008
-
Now you need to tell Visual C++ where the files are located. In Visual C++ Express 2008, navigate to Tools > Options > Projects and Solutions > VC++ Directories:
-
Select Platform Win32 (Be sure that all your entries are before any SDK folder!):
-
Select Include Files, press the new folder button and add the folder
<personal folder>\shared\include
to the list. <-- note the 'shared' and not 'win32' -
Select Library Files, press the new folder button and add the folder
<personal folder>\win32\library
to the list.
-
Select Include Files, press the new folder button and add the folder
-
Select Platform x64 (Skip if it isn't available! Again be sure that all your entries are before any SDK folder!) :
-
Select Include Files, press the new folder button and add the folder
<personal folder>\shared\include
to the list. -
Select Library Files, press the new folder button and add the folder
<personal folder>\win64\library
to the list.
-
Select Include Files, press the new folder button and add the folder
-
Select Platform Win32 (Be sure that all your entries are before any SDK folder!):
-
Now you need to tell Visual C++ where the files are located. In Visual C++ Express 2008, navigate to Tools > Options > Projects and Solutions > VC++ Directories:
Visual C++ Express 2010
In Visual C++ Express 2010 the options are set in a different way. You can either add them globally for all projects or just for OpenTTD.
To add them globally:
- Click on View > Property Manager
- Expand the openttd project
- For Win32 expand 'Debug | Win32 and right click on Microsoft.Cpp.Win32.user and choose Properties.
- Choose VC++ Directories under Common Properties
- Click on the dropdown next to Include Directories and choose edit.
-
Click the 'New Line' icon at the top, and add the folder
<personal folder>\shared\include
to the list. -
Repeat for Library Directories with
<personal folder>\win32\library
- For x64 click on Debug | x64 > Microsoft.Cpp.x64.user instead. The include path is identical, the library path has x64 instead of win32.
To add them locally:
- Select the platform and configuration you want to modify.
- Right click on the openttd project in the Solution Explorer and choose Properties.
- Choose VC++ Directories under Common Properties
- Click on the dropdown next to Include Directories and choose edit.
-
Click the 'New Line' icon at the top, and add the folder
<personal folder>\shared\include
to the list. -
Repeat for Library Directories with
<personal folder>\win32\library
Subversion
Getting the client
Subversion is needed to download the source (the place where to find the MSVC project file. If you want an easy, GUI subversion client, download and install TortoiseSVN.
Make the directory
Make a directory called "ottdsrc" in your C:\ drive. It is important to make a directory without spaces since Compiling on Windows using MinGW (the program used later for making a bundle) can only switch to directories without spaces. This will be used as a place to download the source to.
Download the source
To download the actual source of OpenTTD, right click inside the folder C:\ottdsrc
, then go to SVN Checkout.
In SVN Checkout, make sure you have the url of the OpenTTD trunk source (svn://svn.openttd.org/trunk) in the "URL of Repository" box.
To get the latest revision, get the HEAD Revision. To get an older/different revision, highlight the "Revision" box and type in the revision number you want specifically. For now, you can just download the HEAD revision, unless you need another revision. This takes about 5-20 minutes depending on your internet.
Compiling
A compile can take anywhere from ~5 minutes to ~20 or more minutes depending on how fast your system is. The "generating code" part at the end takes the longest (about 20% of the entire compile), so do not close MSVC because it looks like it has stopped.
Debug (Debugging crashes only):
-
Open
projects/openttd_vs90.sln
. This will open your IDE with the project loaded. -
Go to
Build -> Configuration Manager
and check if it is set toDebug
. By default, it should be. -
Right-click on openttd (project) -> Properties -> C/C++ -> -> General -> Additional Include Directories. Add the DirectX headers subdirectory (Usually,
C:\Program Files\Microsoft DirectX SDK (August 2007)\Include
) -
Press
F7
, or go toBuild -> Build Solution
.
-
Open
Release (Recommended):
-
Open
projects/openttd_vs90.sln
. This will open your IDE with the project loaded. -
Go to
Build -> Configuration Manager
and selectRelease for OpenTTD
. -
Right-click on openttd (project) -> Properties -> C/C++ -> -> General -> Additional Include Directories. Add the DirectX headers subdirectory (Usually,
C:\Program Files\Microsoft DirectX SDK (August 2007)\Include
) -
For Win32:
-
Right-click on openttd (project) -> Properties -> Linker -> General -> Additional Library Directories. Add the DirectX SDK Lib subdirectory (Usually,
C:\Program Files\Microsoft DirectX SDK (August 2007)\Lib\x86
)
-
Right-click on openttd (project) -> Properties -> Linker -> General -> Additional Library Directories. Add the DirectX SDK Lib subdirectory (Usually,
-
For Win64:
-
Right-click on openttd (project) -> Properties -> Linker -> General -> Additional Library Directories. Add the DirectX SDK Lib subdirectory (Usually,
C:\Program Files\Microsoft DirectX SDK (August 2007)\Lib\x64
)
-
Right-click on openttd (project) -> Properties -> Linker -> General -> Additional Library Directories. Add the DirectX SDK Lib subdirectory (Usually,
- Make sure to press Apply then press Ok, this is important.
-
Press
F7
, or go toBuild -> Build Solution
.
-
Open
Compile Problems
Missing files for compilation
Problem
It is possible some files are missing for compilation, eg. rev.cpp
. These files aren't included with the source, but are generated by a script before compilation, apparently some script didn't run. See the next sub section to fix problems with running these scripts.
Input Error: There is no script engine for file extension “.vbs”
Problem
There's an executable (c/w)script which runs your .vbs
scripts, perhaps the reposonsible .dll
isn't registered in your Windows installation. Another possible cause is setting your default program for this file extensionto another application (eg. notepad++) this might give problems while building.
Solutions
First try to solve it by registering the responsible dll in the commandprompt: regsvr32 %systemroot%\system32\vbscript.dll
.
If that doesn't work try to solve it by registering .vbs
through a .reg
file, solution found via and file for XP or Vista/Win7
Where is my completed build
When you do not use make bundle, all files end up in ottdsrc\bin
with the exception of the executable, the executable ends up in ottdsrc\objs\win32\debug
or ottdsrc\objs\win32\release
.
Bundle
This is not necessary in compiling OpenTTD, only if you want to upload your binary publicly. The purpose of this article is to get the equivalent of a "make bundle
" for MSVC builds.
You must have MSYS or Cygwin installed for this to work. To get MSYS, follow this guide. You only need to use the part which says "Setting Up MinGW", "Setting up MSYS" and "Install SVN", then you are good to go. Note that when installing MinGW, you do not need to install the g++ compiler, but you still need to install the candidate.
You will first need to change the directory to your OpenTTD source. Use this command to change directory: cd <directory>
. To change to your new source directory, type cd /c/ottdsrc
Then, enter the command:
make -f Makefile.msvc bundle PLATFORM=Win32
Replace PLATFORM=Win32
with PLATFORM=x64
if you compiled a 64-bit build.
After this is done, you can find the contents in the /bundle
directory. From there, you can make a zip/rar out of the files. Remember, TT-Forums.net[1] only allows files that are less than or equal to 6 MiB.
Running/Debugging the game
Make sure you have either the original game files or our free alternatives Sound Effects Replacement and OpenGFX Readme placed in ~\Documents\OpenTTD\baseset\ , that way they're shared by all your OpenTTD installations and you don't have to copy them to every new installation.
Microsoft® DirectX SDK earlier than August 2007
Information: The DirectX SDK from November 2007 is the first one which supports Microsoft® Visual Studio 2008. But it's also the first version which doesn't support DirectMusic which is needed to compile OpenTTD. That is why we must copy the missing files from an older version, prefered the final one for DirectMusic: 'August 2007'.
Direct download link here (WARNING: Starts download immediately): http://download.microsoft.com/download/3/3/f/33f1af6e-c61b-4f14-a0de-3e9096ed4b3a/dxsdk_aug2007.exe
- Extract (no double-click, do not install) dxsdk_aug2007.exe in an extra directory and you get a file called dxsdk_aug2007.exe (yes that's right, both files have the same name).
- Extract the second dxsdk_aug2007.exe in an extra directory.
- Now copy following 9 files from .\dxsdk_aug2007\dxsdk_aug2007\Include\ to <personal folder>\shared\include (note: Please update the paths as necessary):
- dls1.h
- dmdls.h
- dmerror.h
- dmksctrl.h
- dmplugin.h
- dmusbuff.h
- dmusicc.h
- dmusicf.h
- dmusici.h
Credits
- OpenTTD Developers for the great game.
- Microsoft® for the the SDKs and Visual C++ 2008 Express Edition.
- Sebastian and Desolator (aka Mircea Chirea) for creating/updating the Microsoft® Visual C++ 2005 Express guide.
- 64 bit instructions taken from http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets