Compiling under VS2008: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
(98 intermediate revisions by 44 users not shown)
Line 1: Line 1:
In this tutorial you will learn how to get the [[Source SDK]] up and running with Microsoft Visual Studio 2008. There are several things you're going to have to do to get it working.
{{LanguageBar}}
{{TabsBar|main=Visual Studio}}
{{Outdated sdk|{{src07|4.1}}|newer-sdk-equivalent=[[Compiler choices]]}}


== Create a new project ==
{{toc-right}}
If you haven't already, you need to create a new SDK project.


* Under the tool section of your steam client, launch the Source SDK.
In this tutorial you will learn how to get the [[Source SDK]] to compile under '''Visual Studio 2008''' and/or '''Visual C++ Express 2008'''. There are several things you're going to have to do to get it working. Before you begin, [[Create a Mod|create your mod]].
* Click "[[Create a Mod]]".
* Choose one of the options(in this tutorial I used Hl2MP).
* Select a path to install it to, preferably not in your Steam folders. It's recommend <code>C:/*MODNAMEHERE*</code>, as it'll be easy for you or anyone else to find if you need some files.


You should now have a fresh SDK installation in the folder you selected.
{{warning|This page assumes you are compiling the latest Orange Box source code.}}


== Copying files ==
{{tip|You do ''not'' need to install any Platform SDKs. Both VS2008 and VCE2008 come with the required libraries.}}
To do all of this in a non-destructive way, we must copy our VS2005 files and make a new solution.


* Copy <code>src/Game_HL2MP-2005.sln</code> and rename the copy to <code>Game_HL2MP-2008.sln</code>.
{{note|You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!}}
* Copy <code>src/cl_dll/client_hl2mp-2005.vcproj</code> and rename the copy to <code>client_hl2mp-2008.vcproj</code>.
* Copy <code>src/dlls/server_hl2mp-2005.vcproj</code> and rename the copy to <code>server_hl2mp-2008.vcproj</code>.


== Install Visual Studio 2008 ==


{{Note|If you are using the Orange box source code, you will need to copy <code>Game_HL2MP-2005.sln</code>, <code>game\client\client_hl2mp-2005.vcproj</code> and <code>game\server\server_hl2mp-2005.vcproj</code> and replace '''2005''' with '''2008'''.}}
If you do not have Visual Studio 2008, you can [http://download.microsoft.com/download/E/8/E/E8EEB394-7F42-4963-A2D8-29559B738298/VS2008ExpressWithSP1ENUX1504728.iso download Visual Express 2008] for free from Microsoft.
This download comes with SP1 so you do not need the information below in that case.


You'll now have created a new project to work with. This is important, as you don't want to go around messing up your entire SDK installation if you mess up.
=== Upgrade to Service Pack 1 ===


== Modifying files ==
If you installed VS2008 before August 2008 it will probably need updating to SP1. The service pack will presumably be offered through Windows Update eventually, but for now you'll need to manually download it:
With that done, we can now go ahead and modify our setup.


* Open the newly created <code>Game_HL2MP-2008.sln</code> in a text editor.
* [http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E Visual Studio update]
* You should see 2 strings, <code>cl_dll\client_hl2mp-2005.vcproj</code> and <code>dlls\server_hl2mp-2005.vcproj</code>. Change the 2005 in both of them to 2008.
* [http://www.microsoft.com/downloads/details.aspx?FamilyId=F3FBB04E-92C2-4701-B4BA-92E26E408569 Visual C++ Express update] (choose vcsetup.exe)
{{Note|If you are using the Orange Box version of the source code, the paths will be different, but you can still simply change the 2005 to 2008.}}


* Open <code>Game_HL2MP-2008.sln</code> in Visual Studio 2008. You will be prompted to upgrade the project files.
Service Pack 1 improves error reporting and fixes issues with Intellisense database corruption (" cannot update program database" / "Cannot open program database file"), alongside other improvements not directly relevant to the Source SDK.
* At the first section of the upgrade process, you are asked if you want to create a backup before converting.
* We want to select "No". Wait for the conversion process to complete, then press the Finish button. You should now automatically launch into your newly converted solution.


We don't need to backup anything because we did a better manual backup ourselves. It's OK if the conversion process tells you that it complied with a few warnings, as this is normal. This SDK was originally meant for VS2005, so there's bound to be some problems.
== Open the solution ==


== Setting up Mircosoft SDK's==
# Launch your copy of '''Microsoft Visual Studio'''.
You will now need to install the following, The DirectX SDK and Microsoft Platform SDK then follow the instructions below to include them in the build process
# Select '''File-&gt;Open Solution''' from the menu and open the '''Game_Episodic-2008.sln''' solution located in your mod's <code>src</code> directory, select the one that matches your version of '''Microsoft Visual Studio'''.  Note the "HL2" portion of the file name will correspond to the selection you made in the mod creation step.  If you selected mod from scratch, "Scratch" will appear there instead.


=== Files ===
=== Upgrade the project files ===
*[http://msdn.microsoft.com/directx/sdk/ MS DirectX SDK]


This is only the case if the 2008 solution/projects are not available.


Go to Tools - Options: Projects and Solutions - VC++ Directories
Visual Studio will prompt you to upgrade the project files. If you've been working on your mod in a previous version of the VS you'll probably want to have it make a backup of the project file, though this is a good time to do a backup of the entire source tree yourself anyway. Otherwise you can just do the conversion in-place.
{{Note|Vista users, having downloaded the Microsoft Windows SDK, will not have a path containing Microsoft Platform SDK. The correct path (if the Windows SDK is installed with the download above and it's default install paths), to substitute in to the appropriate paths below, appears to be "...\Microsoft SDKs\Windows\vx.x\..." Installing the Windows SDK does not make a difference in paths to the DirectX SDK, except the version may not have been released in the same month and hence may not have the same month in parenthesis in the folder path.}}


* Then select "Include files" and add "...\Microsoft DirectX SDK (November 2007)\Include"
{{tip|For clarity, you may want to rename the project file from <code>whatever_2005.sln</code> to <code>whatever_2008.sln</code>.}}


* Then select "Library files" and add "...\Microsoft DirectX SDK (November 2007)\Lib\x86"
== Fix debug compilation ==


Finally, in the Solution Explorer right click 'client_hl2', and select Properties, then:  
{{tip|You don't actually need to compile a debug build thanks to the PDB files Visual Studio generates in release mode. Sometimes you'll find that variables won't be unscrambled correctly when you use a PDB however, and you also miss out on all of Valve's useful <code>#ifdef DEBUG</code>'ed code. It's up to you: debug builds are slower and larger than release builds.}}


* In the client_hl2 properties window, navigate to Linker -> Input
Right-click > Properties on the Server and Client projects (multi-select both of them). Making sure that you are working on the Debug configuration (top left of properties dialogue- you may need to first select the Configuration Properties item in the list on the left) change ''Configuration Properties > Linker > Input > Ignore Specific Library'' to '''<code>libc;libcd;libcmtd</code>''' (an extra 'd' on the end).
* Select the 'Additional Properties' row. Then click the '...' on the right hand side of the row
* If there is already an entry here, take a new line after it (a space will suffice if you cannot create a new line), and type ' user32.lib ' without the quotes.
* Repeat these steps for 'server_hl2'


== Important changes ==
A function also needs commenting out from <code>public\tier0\memoverride.cpp</code>:


We need to make sure we're compiling in Release (VS2008, in fact does not compile debug mode)
<source lang=cpp>
void __cdecl _invalid_parameter_noinfo(void)
{
    Assert(0);
}
</source>


* Right-click on "Solution Game_HL2MP-2008" in your Solution Explorer and select Properties.
Get rid of the whole thing. Remember to launch your mod with <code>-allowdebug</code>!
* Click the Configuration Properties option.
* Under the Configuration tab in the table that appears on the right of the window, use the selection box to change or verify that both solutions are set to "Release". Once you've done this, press Apply, then OK.


You might think we're all done, but if you compiled right now, you'd find that you still get errors and whole lot of warnings. The warnings are just fine, but those stupid errors are the only thing preventing you from compiling correctly. Luckily, there's an easy fix; just compile the 'client_hl2mp' first, then the 'server_hl2mp' - it's that simple!
== Fix missing symbols ==
 
If you see missing symbols such as: ConVar_Register you'll need to add tier3.lib to the Link Libraries folder.
 
== Disable /Wp64 ==
 
You'll receive warnings about the <code>Wp64</code> option. You can ignore them if you like, but it's a simple matter to sort them out too: right-click > Properties on both the Server and Client projects, then change ''Configuration Properties > C/C++ > General > Detect 64-bit Portability Issues'' to '''<code>No</code>'''.
 
== Install the DirectX SDK (for shaders) ==
 
To create new [[shader]]s you will need the [http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=24a541d6-0486-4453-8641-1eee9e21b282 MS DirectX SDK (March 2009)]. Once installed, follow the instructions below to incorporate it with your project.
 
# Go to Tools - Options: Projects and Solutions - VC++ Directories
# Select "Include files" and add "...\Microsoft DirectX SDK (November 2008)\Include"
# Select "Library files" and add "...\Microsoft DirectX SDK (November 2008)\Lib\x86"
# In the Solution Explorer, right click the client project and select Properties. Navigate to the Linker -> Input pane.
# Select the 'Additional Properties' row and click the '...' on the right hand side of the row
# Add <code>user32.lib</code> to the list that appears. Separate it from any other entries with a new line.
# Repeat for the server.
 
== Missing vc80.pdb ==
 
You may encounter these warnings after trying to compile one of the other tool/library projects included in the SDK. You see it because your code has been compiled with VS2008 (VC9), whereas the SDK's .libs were compiled with VS2005 (VC8).
 
The warnings prevent the compilation of PDB files. The easiest way to fix them is to build the library which is generating them yourself!
<!-- I've not seen anyone who says the below works
 
# Go to ''Tools > Options >  Projects and Solutions > Create and execute''
# Set the maximum number of parallel projectbuilds to 1
 
You may also have to close the task <code>mspdbsrc.exe</code>.
 
Visual Studio 2008 users should go to ''Tools > Options > Projects and Solutions > Build and Run'', and then set Maximum number of parallel projectbuilds to 1.-->
 
== Fix grenade_tripmine.cpp ==
 
If you've started from hl2mp code and get error C2039: 'OnTakeDamage_Alive' : is not a member of 'CBaseGrenade', go to '''line 31''' in <code>game/shared/basegrenade_shared.h</code>:
 
<source lang="cpp">
//Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
class CBaseGrenade :
#if defined( HL2_EPISODIC )
public CBaseCombatCharacter
#else
public CBaseAnimating
#endif
#if defined( GAME_DLL )
, public CDefaultPlayerPickupVPhysics
#endif
{ //Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
DECLARE_CLASS( CBaseGrenade, CBaseAnimating );
</source>
 
Replace this with:
<source lang="cpp">
  //Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
#if defined( HL2_EPISODIC ) || defined ( HL2MP )
#define GRENADEBASECLASS CBaseCombatCharacter
#else
#define GRENADEBASECLASS CBaseAnimating
#endif
class CBaseGrenade : public GRENADEBASECLASS
#if defined( GAME_DLL )
, public CDefaultPlayerPickupVPhysics
#endif
{ //Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
DECLARE_CLASS( CBaseGrenade, GRENADEBASECLASS );
</source>
 
Don't forget to add HL2_EPISODIC to your preprocessor definitions!
 
== Fix a compiler crash ==
 
{{note|'''This fix applies only to [[Alien Swarm]] source code'''}}
 
The 2008 compiler crashes on '''line 341''' of <code>client/c_vguiscreen.cpp</code>:
dist = c_x / tan( M_PI * scaled_fov / 360.0 );
 
Replace it with:
 
float dist_denom = tan( M_PI * scaled_fov / 360.0f );
dist = c_x / dist_denom;
 
This can also be fixed using the following :
dist = c_x / (float)tan(M_PI * scaled_fov / 360.0f);
 
== See also ==
* [[Compiling under VS2005]]
* [[Compiling under VS2010]]
* [[My First Mod]]


Your SDK installation should now be fully operational. You might still get some warnings, but you shouldn't get any more errors on your first build if you followed these steps. I recommend you build now while the installation is still fresh so you don't have to do this again and so you know everything is working the way it should. If you are still getting errors, keep retrying this tutorial until you don't anymore, as I've confirmed this works.


[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Programming]]
[[Category:Programming]]
[[Category:Source SDK FAQ]]

Latest revision as of 05:32, 22 September 2024

English (en)Русский (ru)中文 (zh)Translate (Translate)
Visual Studio compilers: edit
Ambox warning yellow.png
This page was written for Source 2007 Source 2007 or earlier. It may not be applicable to newer versions of the Source SDK.
For more up-to-date information, see Compiler choices.

In this tutorial you will learn how to get the Source SDK to compile under Visual Studio 2008 and/or Visual C++ Express 2008. There are several things you're going to have to do to get it working. Before you begin, create your mod.

Warning.pngWarning:This page assumes you are compiling the latest Orange Box source code.
Tip.pngTip:You do not need to install any Platform SDKs. Both VS2008 and VCE2008 come with the required libraries.
Note.pngNote:You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!

Install Visual Studio 2008

If you do not have Visual Studio 2008, you can download Visual Express 2008 for free from Microsoft. This download comes with SP1 so you do not need the information below in that case.

Upgrade to Service Pack 1

If you installed VS2008 before August 2008 it will probably need updating to SP1. The service pack will presumably be offered through Windows Update eventually, but for now you'll need to manually download it:

Service Pack 1 improves error reporting and fixes issues with Intellisense database corruption (" cannot update program database" / "Cannot open program database file"), alongside other improvements not directly relevant to the Source SDK.

Open the solution

  1. Launch your copy of Microsoft Visual Studio.
  2. Select File->Open Solution from the menu and open the Game_Episodic-2008.sln solution located in your mod's src directory, select the one that matches your version of Microsoft Visual Studio. Note the "HL2" portion of the file name will correspond to the selection you made in the mod creation step. If you selected mod from scratch, "Scratch" will appear there instead.

Upgrade the project files

This is only the case if the 2008 solution/projects are not available.

Visual Studio will prompt you to upgrade the project files. If you've been working on your mod in a previous version of the VS you'll probably want to have it make a backup of the project file, though this is a good time to do a backup of the entire source tree yourself anyway. Otherwise you can just do the conversion in-place.

Tip.pngTip:For clarity, you may want to rename the project file from whatever_2005.sln to whatever_2008.sln.

Fix debug compilation

Tip.pngTip:You don't actually need to compile a debug build thanks to the PDB files Visual Studio generates in release mode. Sometimes you'll find that variables won't be unscrambled correctly when you use a PDB however, and you also miss out on all of Valve's useful #ifdef DEBUG'ed code. It's up to you: debug builds are slower and larger than release builds.

Right-click > Properties on the Server and Client projects (multi-select both of them). Making sure that you are working on the Debug configuration (top left of properties dialogue- you may need to first select the Configuration Properties item in the list on the left) change Configuration Properties > Linker > Input > Ignore Specific Library to libc;libcd;libcmtd (an extra 'd' on the end).

A function also needs commenting out from public\tier0\memoverride.cpp:

void __cdecl _invalid_parameter_noinfo(void)
{
    Assert(0);
}

Get rid of the whole thing. Remember to launch your mod with -allowdebug!

Fix missing symbols

If you see missing symbols such as: ConVar_Register you'll need to add tier3.lib to the Link Libraries folder.

Disable /Wp64

You'll receive warnings about the Wp64 option. You can ignore them if you like, but it's a simple matter to sort them out too: right-click > Properties on both the Server and Client projects, then change Configuration Properties > C/C++ > General > Detect 64-bit Portability Issues to No.

Install the DirectX SDK (for shaders)

To create new shaders you will need the MS DirectX SDK (March 2009). Once installed, follow the instructions below to incorporate it with your project.

  1. Go to Tools - Options: Projects and Solutions - VC++ Directories
  2. Select "Include files" and add "...\Microsoft DirectX SDK (November 2008)\Include"
  3. Select "Library files" and add "...\Microsoft DirectX SDK (November 2008)\Lib\x86"
  4. In the Solution Explorer, right click the client project and select Properties. Navigate to the Linker -> Input pane.
  5. Select the 'Additional Properties' row and click the '...' on the right hand side of the row
  6. Add user32.lib to the list that appears. Separate it from any other entries with a new line.
  7. Repeat for the server.

Missing vc80.pdb

You may encounter these warnings after trying to compile one of the other tool/library projects included in the SDK. You see it because your code has been compiled with VS2008 (VC9), whereas the SDK's .libs were compiled with VS2005 (VC8).

The warnings prevent the compilation of PDB files. The easiest way to fix them is to build the library which is generating them yourself!

Fix grenade_tripmine.cpp

If you've started from hl2mp code and get error C2039: 'OnTakeDamage_Alive' : is not a member of 'CBaseGrenade', go to line 31 in game/shared/basegrenade_shared.h:

 //Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
 class CBaseGrenade : 
 	#if defined( HL2_EPISODIC )
 		public CBaseCombatCharacter
 	#else
 		public CBaseAnimating
 	#endif
 	#if defined( GAME_DLL )
 		, public CDefaultPlayerPickupVPhysics
 	#endif
 {		//Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
 	DECLARE_CLASS( CBaseGrenade, CBaseAnimating );

Replace this with:

  //Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
#if defined( HL2_EPISODIC ) || defined ( HL2MP )
#define GRENADEBASECLASS CBaseCombatCharacter
#else
#define GRENADEBASECLASS CBaseAnimating
#endif
 class CBaseGrenade : public GRENADEBASECLASS
 	#if defined( GAME_DLL )
 		, public CDefaultPlayerPickupVPhysics
 	#endif
 {		//Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
 		DECLARE_CLASS( CBaseGrenade, GRENADEBASECLASS );

Don't forget to add HL2_EPISODIC to your preprocessor definitions!

Fix a compiler crash

Note.pngNote:This fix applies only to Alien Swarm source code

The 2008 compiler crashes on line 341 of client/c_vguiscreen.cpp:

dist = c_x / tan( M_PI * scaled_fov / 360.0 );	

Replace it with:

float dist_denom = tan( M_PI * scaled_fov / 360.0f ); 	 
dist = c_x / dist_denom;

This can also be fixed using the following :

dist = c_x / (float)tan(M_PI * scaled_fov / 360.0f);

See also