Compiling on Windows using Microsoft Visual C++ 2008/2010

From OpenTTD
Jump to: navigation, search
Notice.png

Note
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

...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:

Installing

Install screen

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.
Minimal SDK options

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.
Notice.png

Note
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® 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 to Projects 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 remove WIN32_ENABLE_DIRECTMUSIC_SUPPORT preprocessor definition.
Preprocessor settings
  • Navigate to Configuration properties -> Linker -> Input -> Additional Dependencies and remove dxguid.lib library. note: this may no longer be necessary
Linker settings

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.

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 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.

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++ under Configuration 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++ under Configuration 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

The SVN Checkout Box

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 MSYS (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 to Debug. 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 to Build -> Build Solution.

Release (Recommended):

  • Open projects/openttd_vs90.sln. This will open your IDE with the project loaded.
  • Go to Build -> Configuration Manager and select Release 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)
  • 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)
  • Make sure to press Apply then press Ok, this is important.
  • Press F7, or go to Build -> Build Solution.

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.
Notice.png

Note
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 OpenSFX and OpenGFX 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'.

  • 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

Personal tools