Compiling under VS2008: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(added link to VC++ 2008 Express)
(updated to reflect new SLNs)
Line 1: Line 1:
{{toc-right}}
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]].
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]].


{{note|'''There is no need to have the Microsoft Platform SDK installed, as VC2008 already contains the needed files.'''}}
{{warning|This page assumes you are compiling the latest Orange Box source code.}}
 
{{tip|You do ''not'' need to install any Platform SDKs. Both VS2008 and VCE2008 come with the required libraries.}}


{{note|You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!}}
{{note|You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!}}


== Installing Visual Studio 2008 ==
== Install Visual Studio 2008 ==


If you do not have Visual Studio 2008, you can [http://www.microsoft.com/express/download/ download Visual C++ Express 2008] for free.
If you do not have Visual Studio 2008, you can [http://www.microsoft.com/express/download/ download Visual C++ Express 2008] for free from Microsoft.


== Upgrade to Service Pack 1 ==
=== 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:
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:
Line 24: Line 28:
{{tip|For clarity, you may want to rename the project file from <code>whatever_2005.sln</code> to <code>whatever_2008.sln</code>.}}
{{tip|For clarity, you may want to rename the project file from <code>whatever_2005.sln</code> to <code>whatever_2008.sln</code>.}}


== Fix a compiler crash ==
== Fix debug compilation ==
 
{{note|'''In the latest "OrangeBox Source SDK Beta" this fix is no longer needed!'''}}
 
The 2008 compiler crashes on '''line 348''' ([[Orange box|OB]] code) of <code>client/c_vguiscreen.cpp</code> ([http://developer.valvesoftware.com/cgi-bin/bugzilla/show_bug.cgi?id=214 bug report here]):
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);
 
== Fix file copying ==
 
Right-click > Properties on the Server and Client projects. You will need to do this for both the Release and the Debug configuration; four times in all.


# Navigate to ''Configuration Properties > Custom Build Step''.
''You don't actually need to compile in debug mode to debug your mod thanks to the PDB files Visual Studio generates in release mode. If you do want to make a debug build however:''
# Click on ''Command Line'', then click on the ... button that appears on the right.
# Replace the contents of the new dialogue with the first code block below.
# Click on ''Outputs'' and paste in the second code block below.


{{warning|Remember to change "client" to "server" in the code blocks below when appropriate, and, of course, to fill in the actual target destination.}}
Right-click > Properties on the Server and Client projects. Making sure that you are working on the Debug configuration (top left of properties dialogue) vhange ''Configuration Properties > Linker > Input > Ignore Specific Library'' to '''<code>libc;libcd;libcmtd</code>''' (an extra 'd' on the end).
{{note|The "<YOUR MOD PATH>" is the path of your "..steamapps\SourceMods\<Your Mod>" directory, and not the directory of your Visual Studio Project.}}


=== Command Line ===
<!--# Change ''Configuration Properties > C/C++ > General > Debug Information Format'' to '''<code>Program Database (/Zi)</code>'''.
# Change ''Configuration Properties > C/C++ > Code Generation > Runtime Library'' to '''<code>Multi-threaded (/MT)</code>'''.-->


if exist "<YOUR MOD PATH>\bin\client.dll" attrib -r "<YOUR MOD PATH>\bin\client.dll"
A function also needs commenting out at '''line 727''' ([[Orange box|OB]] code) of <code>server/memoverride.cpp</code>:
copy "$(TargetDir)"client.dll "<YOUR MOD PATH>\bin\"
if exist "<YOUR MOD PATH>\bin\client.pdb" attrib -r "<YOUR MOD PATH>\bin\client.pdb"
if exist "$(TargetDir)"client.pdb copy "$(TargetDir)"client.pdb "<YOUR MOD PATH>\bin\"
 
=== Outputs ===
 
<YOUR MOD PATH>\bin\client.dll;<YOUR MOD PATH>\bin\client.pdb
 
 
''If errors persist is possible that you have a corrupted bin file instead a bin folder at you steam mod path, delete it and recompile or create your mod project again.''
 
== Fix debug compilation ==
 
Right-click > Properties on the Server and Client projects. Making sure that you are working on the Debug configuration (top left of properties dialogue):
 
# Change ''Configuration Properties > C/C++ > General > Debug Information Format'' to '''<code>Program Database (/Zi)</code>'''.
# Change ''Configuration Properties > C/C++ > Code Generation > Runtime Library'' to '''<code>Multi-threaded (/MT)</code>'''.
# Change ''Configuration Properties > Linker > Input > Ignore Specific Library'' to '''<code>libc;libcd;libcmtd</code>''' (just an extra 'd' on the end, so it looks exactly like this).
 
Lastly, a function needs commenting out at '''line 727''' ([[Orange box|OB]] code) of <code>server/memoverride.cpp</code>:


  void __cdecl _invalid_parameter_noinfo(void)
  void __cdecl _invalid_parameter_noinfo(void)
Line 81: Line 44:
  }
  }


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


== Fix missing symbols ==
== Fix missing symbols ==
Line 90: Line 53:


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>'''.
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>'''.
== Fix "missing CTeamTrainWatcher" error ==
The Orange Box multiplayer client project is missing a few files. It will compile but not load a map. Single-player mods are not affected by this issue.
'''Solution: '''
* In Visual Studio, right click on the Source Files Folder in the Client project
* Select add existing
* Select '''c_team_train_watcher.h''' and  '''c_team_train_watcher.cpp'''
See [[Error on map: "Client missing DT class CTeamTrainWatcher"]] for more detail on this issue.


== Install the DirectX SDK (for shaders) ==
== Install the DirectX SDK (for shaders) ==
Line 119: Line 71:
You may encounter this error if try to compile more than one solution into the same folder. To fix it:
You may encounter this error if try to compile more than one solution into the same folder. To fix it:


# Go to {{key|Tools > Options >  Projects and Solutions > Create and execute}}
# Go to ''Tools > Options >  Projects and Solutions > Create and execute''
# Set the maximum number of parallel projectbuilds to 1
# Set the maximum number of parallel projectbuilds to 1


You may also have to close the task <code>mspdbsrc.exe</code>.
You may also have to close the task <code>mspdbsrc.exe</code>.


For VS2008 Users you should go to {{Key|Tools > Options > Projects and Solutions > Build and Run}}, and then set Maximum number of parallel projectbuilds to 1.
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.


{{otherlang:en}}
{{otherlang:en}}

Revision as of 12:28, 16 June 2009

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 C++ Express 2008 for free from Microsoft.

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, alongside other improvements not directly relevant to the Source SDK.

Upgrade the project files

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

You don't actually need to compile in debug mode to debug your mod thanks to the PDB files Visual Studio generates in release mode. If you do want to make a debug build however:

Right-click > Properties on the Server and Client projects. Making sure that you are working on the Debug configuration (top left of properties dialogue) vhange Configuration Properties > Linker > Input > Ignore Specific Library to libc;libcd;libcmtd (an extra 'd' on the end).


A function also needs commenting out at line 727 (OB code) of server/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 below 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 'client_hl2', and select Properties.
  5. In the client_hl2 properties window, navigate to Linker - Input
  6. Select the 'Additional Properties' row and click the '...' on the right hand side of the row
  7. 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.
  8. Repeat these steps for the server.

Missing vc80.pdb

You may encounter this error if try to compile more than one solution into the same folder. To fix it:

  1. Go to Tools > Options > Projects and Solutions > Create and execute
  2. Set the maximum number of parallel projectbuilds to 1

You may also have to close the task mspdbsrc.exe.

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.

Template:Otherlang:en Template:Otherlang:en:ru