User:Roujin/Microsoft Visual C++ 2010

From OpenTTD
< User:Roujin
Revision as of 18:30, 27 April 2011 by Roujin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I will be using this subpage of my user page to update the Visual Studio 2008 guide to Visual Studio 2010. This is a WIP, please do not interfere.




This article gets you started on compiling OpenTTD using Microsoft Visual C++ 2010. This guide was created using Microsoft Visual Studio 2010 Ultimate Edition, but you can use any edition of Visual Studio 2010 to compile OpenTTD, including the free Express Edition.

Contents

Required software

Notice.png

Note
64-bit tools are not available on Visual C++ Express by default. To enable 64-bit tools on Visual C++ Express, install the Windows Software Development Kit (SDK) in addition to Visual C++ Express. Otherwise, an error occurs when you attempt to configure a project to target a 64-bit platform using Visual C++ Express. (Source)

Installing

Microsoft® Visual C++ 2010 Express Edition

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.

Subversion

Subversion is needed to download the OpenTTD source code. If you want an easy, GUI subversion client, download and install TortoiseSVN. This guide in the following assumes that you are using TortoiseSVN.

openttd_useful.zip

Extract the openttd-useful.zip file and copy the content to some folder on your hard disk. This folder will be called <openttd-useful folder> in this guide. Remember the folder for the Setup step later on.

Checking out the source code

The SVN Checkout Box

Make the directory

Make a directory somewhere where the source code will be downloaded to, for example C:\ottdsrc. This directory will be called <openttd folder> in this guide. If you want to make a bundle later on, this directory must not contain any spaces since MSYS can only switch to directories without spaces.

Download the source

To download the actual source of OpenTTD, right click inside your <openttd folder>, then click SVN Checkout.

In SVN Checkout, enter the url of the OpenTTD trunk source (svn://svn.openttd.org/trunk) in the URL of Repository box.

Make sure that the Checkout Directory box contains your <openttd folder>.

To get the latest revision, select HEAD Revision. To get an older/different revision, select Revision and enter the revision number you want into the box. For now, you can just download the HEAD revision, unless you need another revision (if you want to apply a patch, you need to download the revision that patch was made for).

This can take a while, depending on your internet connection.

Setup

  • Open <openttd folder>\projects\openttd_vs100.vcxproj. This will open Visual Studio 2010 with the project loaded.
  • In the Solution Explorer on the left side of the screen, right click on openttd then select Properties.
    • Navigate to Configuration Properties -> VC++ Directories
      • At the Top of the Window, select All Configurations for Configuration and Win32 for Platform
        • Edit Include Directories to contain <openttd-useful folder>\shared\include
        • Edit Library Directories to contain <openttd-useful folder>\win32\library
      • Now select x64 for Platform
        • Edit Include Directories to contain <openttd-useful folder>\shared\include
        • Edit Library Directories to contain <openttd-useful folder>\win64\library
    • Note: Don't forget to replace <openttd-useful folder> in the above instructions with the folder where you extracted openttd-useful.zip.
    • Navigate to Configuration Properties -> C/C++ -> Preprocessor
      • Select Configuration Debug and Platform Win32
        • Remove WIN32_ENABLE_DIRECTMUSIC_SUPPORT from Preprocessor Definitions
      • Select Configuration Release and Platform Win32
        • Remove WIN32_ENABLE_DIRECTMUSIC_SUPPORT from Preprocessor Definitions
    • Note: Instead of removing these definitions, you can instead install an old version of Microsoft DirectX SDK which supports DirectMusic. Please follow the instructions in the Visual Studio 2008 guide if you want to do so, however this is not necessary anymore in order to get music.
  • Make sure all changes you made are applied (always click 'Yes' when prompted if you want to save the changes), then close the Properties window.

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 Visual Studio because it looks like it has stopped.

Debug (Debugging crashes only):

  • At the top of the window, there are two dropdown menus. Select Debug for the left one and either Win32 or x64 for the right one, depending on whether you want a 32 bit or 64 bit binary.
  • Press F7, or go to Build -> Build Solution.

Release (Recommended):

  • At the top of the window, there are two dropdown menus. Select Release for the left one and either Win32 or x64 for the right one, depending on whether you want a 32 bit or 64 bit binary.
  • Press F7, or go to Build -> Build Solution.

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 4 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\data\ , that way they're shared by all your OpenTTD installations and you don't have to copy them to every new installation.

Credits

  • OpenTTD Developers for the great game.
  • Microsoft® for the the SDKs and Visual C++ 2010 Express Edition.
  • Sebastian and Desolator (aka Mircea Chirea) for creating/updating the Microsoft® Visual C++ 2005 Express guide.
  • Roujin for yet again updating the guide to Microsoft® Visual Studio 2010

TODO: Uncomment categories when finished.

Personal tools