Compiling under VS2008: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added fix for comiling in debug)
(cleanup)
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.
In this tutorial you will learn how to get the [[Source SDK]] to compile under '''Visual Studio 2008''' and '''Visual C++ Express 2008'''. There are several things you're going to have to do to get it working. Before you being, [[Create a Mod|create you mod]].


== Creating a New Source Mod ==
{{note|You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!}}
If you haven't already, you need to create a new Source mod. The [[Create a Mod]] tutorial goes over in detail how to do this.


== Modifying Files - Migrating From VS2005==
== Upgrade the project files ==
To do all of this in a non-destructive way, we must copy our VS2005 files and make a new solution. If you've just created your mod, you do not need to make copies of the files mentioned below.


* Copy <code>src/Game_HL2MP-2005.sln</code> and rename the copy to <code>Game_HL2MP-2008.sln</code>.
Visual Studio will prompt you to upgrade the project files. If you've been working on your mod in a previous version you'll probably want to have it make a backup (you may as well do a full backup yourself though); otherwise you can just do the conversion in-place.
* 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>.


{{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'''.}}
{{tip|For clarity, you may want to rename the project file from <code>whatever_2005.sln</code> to <code>whatever_2008.sln</code>.}}


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. With that done, we can now go ahead and modify our setup.
== Fix a compiler crash ==


* Open the newly created <code>Game_HL2MP-2008.sln</code> in a text editor.
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]):
* 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.
{{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.}}
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;
 
== 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''.
# 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.


== Upgrading the Project ==
{{warning|Remember to change "client" to "server" in the code blocks below when appropriate, and, of course, to fill in the actual target destination.}}
* Open <code>Game_HL2MP-2008.sln</code> in Visual Studio 2008. You will be prompted to upgrade the project files.
* 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.
=== Command Line ===


== Installing the DirectX SDK ==
if exist "<YOUR MOD PATH>\bin\client.dll" attrib -r "<YOUR MOD PATH>\bin\client.dll"
For creating new shaders you will need the [http://go.microsoft.com/fwlink/?LinkID=112184&clcid=0x409 MS DirectX SDK (March 2008)]. Once installed, follow the below instructions below to incorporate it with your project.
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\"


* In VS2008 Go to Tools - Options: Projects and Solutions - VC++ Directories
=== Outputs ===
* Select "Include files" and add "...\Microsoft DirectX SDK (March 2008)\Include"
* Select "Library files" and add "...\Microsoft DirectX SDK (March 2008)\Lib\x86"
* In the Solution Explorer right click 'client_hl2', and select Properties.
* In the client_hl2 properties window, navigate to Linker - Input
* Select the 'Additional Properties' row and 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'


== Other Important Changes ==
<YOUR MOD PATH>\bin\client.dll;<YOUR MOD PATH>\bin\client.pdb
Some changes must be made to before a compiling:


The compiler encounters this bug: http://developer.valvesoftware.com/cgi-bin/bugzilla/show_bug.cgi?id=214. This is the fix:
== Fix debug compilation ==
* Inside <code>c_vguiscreen.cpp</code>, locate the following line:
dist = c_x / tan( M_PI * scaled_fov / 360.0 );
This is line 348 in stock OB HL2DM code.
* Is replaced with:
float dist_denom = tan( M_PI * scaled_fov / 360.0f );
dist = c_x / dist_denom;


The solution can now be compiled in Release, but more changes are required for a Debug compile:
Right-click > Properties on the Server and Client projects. Making sure that you are working on the Debug configuration (top left of properties dialogue):


* In the solution explorer, right click on Client (HL2) and select Properties.
# Change ''Configuration Properties > C/C++ > Debug Information Format'' to '''<code>Program Database (/Zi)</code>'''.
* Navigate to Configuration Properties > C/C++ > General
# Change ''Configuration Properties > C/C++ > Code Generation > Runtime Library'' to '''<code>Multi-threaded (/MT)</code>'''.
* Change Debug Information Format from "Program Database for Edit & Continue (/ZI)" to "Program Database (/Zi)"
# Change ''Configuration Properties > Linker > Input > Ignore Specific Library'' to '''<code>libc;libcd;libcmtd</code>''' (just an extra 'd' on the end).
* Navigate to Configuration Properties > C/C++ > Code Generation
* Change Runtime Library from "Multi-threaded Debug (/MTd)" to "Multi-threaded (/MT)"
* Navigate to Configuration Properties > Linker > Input
* Change Ignore Specific Library from "libc;libcd;libcmt" to "libc;libcd;libcmtd"
* Click OK to apply the changes and close the properties window
* repeat these steps for the Server (HL2) project


Finally, a small piece of code must be commented out:
Lastly, a function needs commenting out at '''line 727''' ([[Orange box|OB]] code) of <code>server/memoverride.cpp</code>:
* Inside <code>memoverride.cpp</code>, locate the following block found at line 727 in stock OB code:


  void __cdecl _invalid_parameter_noinfo(void)
  void __cdecl _invalid_parameter_noinfo(void)
Line 70: Line 57:
  }
  }


* Comment out this routine:
Get rid of the whole thing. Remember to launch your mod with <code>-allowdebug</code>!
 
== 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++ > Detect 64-bit Portability Issues'' to '''<code>No</code>'''.
 
== Install the DirectX SDK (for shaders) ==


//void __cdecl _invalid_parameter_noinfo(void)
For creating new [[shader]]s you will need the [http://go.microsoft.com/fwlink/?LinkID=112184&clcid=0x409 MS DirectX SDK (March 2008)]. Once installed, follow the below instructions below to incorporate it with your project.
//{
//   Assert(0);
//}


Compile the Client project before the Server project to avoid errors. The SDK installation should now be fully operational. Warnings may still appear, but there shouldn't be any more errors on the first build if these steps are followed. It is recommended to build now while the installation is still fresh. If errors are still occuring, make sure that all the steps were followed correctly. Also, make sure that you add -allowdebug to the mods launch options in Steam, or you will get an error when you start the game with a debug build.
# In VS2008 Go to Tools - Options: Projects and Solutions - VC++ Directories
# Select "Include files" and add "...\Microsoft DirectX SDK (March 2008)\Include"
# Select "Library files" and add "...\Microsoft DirectX SDK (March 2008)\Lib\x86"
# In the Solution Explorer right click 'client_hl2', and select Properties.
# In the client_hl2 properties window, navigate to Linker - Input
# Select the 'Additional Properties' row and 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'


[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Programming]]
[[Category:Programming]]

Revision as of 09:49, 12 June 2008

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

Note.pngNote:You will still encounter occasional "precompiled header skipped" warnings after following this guide. Don't worry, they're harmless!

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 you'll probably want to have it make a backup (you may as well do a full backup yourself though); 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 a compiler crash

The 2008 compiler crashes on line 348 (OB code) of client/c_vguiscreen.cpp (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;

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.

  1. Navigate to Configuration Properties > Custom Build Step.
  2. Click on Command Line, then click on the ... button that appears on the right.
  3. Replace the contents of the new dialogue with the first code block below.
  4. Click on Outputs and paste in the second code block below.
Warning.pngWarning:Remember to change "client" to "server" in the code blocks below when appropriate, and, of course, to fill in the actual target destination.

Command Line

if exist "<YOUR MOD PATH>\bin\client.dll" attrib -r "<YOUR MOD PATH>\bin\client.dll"
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

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

  1. Change Configuration Properties > C/C++ > Debug Information Format to Program Database (/Zi).
  2. Change Configuration Properties > C/C++ > Code Generation > Runtime Library to Multi-threaded (/MT).
  3. Change Configuration Properties > Linker > Input > Ignore Specific Library to libc;libcd;libcmtd (just an extra 'd' on the end).

Lastly, a function 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!

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++ > Detect 64-bit Portability Issues to No.

Install the DirectX SDK (for shaders)

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

  1. In VS2008 Go to Tools - Options: Projects and Solutions - VC++ Directories
  2. Select "Include files" and add "...\Microsoft DirectX SDK (March 2008)\Include"
  3. Select "Library files" and add "...\Microsoft DirectX SDK (March 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 'server_hl2'