Compiling under VS2005: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Robot: fixing template case.)
(redone, and also extended with some other common errors)
Line 1: Line 1:
{{TOC|left}}
{{toc-right}}
{{clr}}
== Introduction ==
The following is a general guide to getting [[HL2]] compiling under VS 2005. Its important to note that the SDK code for HL2 supports VS2005, but only in the <code>the _2005.sln</code> files. Compiling <code>a _2003.sln</code> under 2005 and visa versa will only generate problems and errors. Older versions of the source code did not support 2005, to get them working with 2005 go [[Compiling under VS2005/Older SDK|here]].
{{clr}}
== What's working ==
=== Single-player ===
*Release - client - VS Studio: '''working''' & playable
*Release - hl - VS Studio: '''working''' & playable
*Release - client - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fulfilled)
*Release - hl - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fulfilled)
{{clr}}
=== Multiplayer ===
*Release - client - VS Studio: '''working'''  & playable
*Release - hl - VS Studio: '''working''' & playable
*Release - client - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fulfilled)
*Release - hl - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fulfilled)
{{clr}}
== Requirements ==
Necessary steps are needed to enable compiling with the Visual Studio C++ 2005 Express Edition:
{{clr}}
=== Files ===
*[http://www.microsoft.com/downloads/details.aspx?FamilyID=ea4894b5-e98d-44f6-842d-e32147237638&DisplayLang=en MS DirectX SDK]
*[http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en Microsoft Platform SDK] For Windows 2000/XP/Server 2003
*[http://www.microsoft.com/downloads/details.aspx?familyid=4377F86D-C913-4B5C-B87E-EF72E5B4E065&displaylang=en Microsoft Windows SDK] For Windows Vista
{{clr}}


=== Setup ===
Visual Studio 2005 is the officially-supported [[Wikipedia:Integrated development environment|IDE]] of the Source SDK, and if all is well you won't need to do anything special to use it. If you're using Visual C++ 2005 Express or if something is awry however, this page should get you up and running. It assumes you are compiling the Orange Box source code.
Go to Tools - Options: Projects and Solutions - VC++ Directories


{{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\v''x.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. }}
== Installing ==


{{note|'''When using Vista 64''', by default the Platform SDK does not install the 32 bit libs. Make sure to select them when you install. Select Developer tools -> Windows Vista Headers and Libraries -> x86 Libraries.}}
If you don't already have VS2005, you can [http://www.microsoft.com/express/2005/download/ download the free C++ Express version from Microsoft]. After it has installed, run Windows Update to patch it. Do this twice if you are using Windows Vista to catch a compatibility update.


* In the upper right drop down box, select "Executable files" and add "...\Microsoft Platform SDK\Bin" (replace with the correct path)
== Windows SDK ==


* Then select "Include files" and add "...\Microsoft Platform SDK\Include" and "...\Microsoft DirectX SDK (June 2008)\Include"
If you're using Visual C++ Express 2005 you will need to install the Windows SDK to compile the game client.


* Then select "Library files" and add "...\Microsoft Platform SDK\Lib" and "...\Microsoft DirectX SDK (June 2008)\Lib\x86"
It doesn't matter which version you download; [http://www.microsoft.com/downloads/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc this one does the job] well enough.  Don't worry that it talks about Vista - it also covers XP. Windows 2000 users however need to download the older [http://www.microsoft.com/downloads/details.aspx?familyid=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5 Platform SDK] instead.


{{Warning|You need to do this for both Debug and Release builds (You can select these at the top in the toolbar. Do the Debug server/client and then do the Release server/client.}}
{{note|You only need the "headers and libraries" component, about half-way through the list that the installer will present. They're about a 20MB download...the complete SDK is over 2GB!}}


* Finally, in the Solution Explorer right click 'client_hl2', and select Properties, then:
{{note|If you are installing on a 64bit OS, remember that it is still the 32bit (x86) libraries that you want. They aren't selected by default.}}
:* In the client_hl2 properties window, navigate to Linker -> Input
:* Select the 'Additional Dependencies' box. Then click the '...' on the right hand side of the box
:* 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', and without the quotes. '''Vista users''' may have to input "user32.lib" and "kernel32.lib" within the double quotes.
:* Repeat these steps for 'server_hl2'
{{clr}}


== Potential problems ==
Once you have the Windows SDK installed, try compiling. If you encounter errors about not being able to find <code>winerror.h</code> then you need to manually tell Visual C++ where the SDK is located.
''Correcting Custom Build Step''


The Custom Build step which copies the DLLs to your mod's directory is incorrect in the 2005 solution. When you attempt to run your game, it will crash upon trying to access <code>gpGlobals</code>, with an access violation at memory location 0x0000038.  
To do this, navigate to ''Tools > Options > Projects and Solutions > VC++ Directories''. Add the Windows SDK's <code>\bin</code> folder to the list. It will probably be:
{{note|Only follow this step if you encounter this issue. Often, it is not required}}


Right-click on the <code>client_sdk</code> project, and go to Configuration Properties -> Custom Build Step -> General. Set the "Command Line" to:
C:\Program Files\Microsoft SDKs\Windows\v6.1\bin


if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll" attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
Click on the drop-down list that currently says "Executable files". You now need to add the <code>\include</code> folder to the 'Includes' list and the <code>\lib</code> folder to the 'Library' list.
if exist "$(TargetDir)"client.dll copy "$(TargetDir)"client.dll "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb" attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
if exist "$(TargetDir)"client.pdb copy "$(TargetDir)"client.pdb "c:\program files\steam\steamapps\SourceMods\MyMod\bin"


Set Outputs to:
{{tip|You'll need to go through this process if you want to use the DirectX SDK too.}}


"c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll";"c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
[[Image:Vc2005 dirs.png|center|Adding the Windows SDK's includes.]]


(In both cases, replace the "MyMod" entry with the actual name of your mod directory.)
== Add dependencies ==


Click "Apply" (you ''will'' lose your changes if you skip this step). At the top-left, bring down the "Configuration" combo box, set it to "Release SDK", and set Command Line and Outputs to the same values. The <code>server_sdk</code>'s custom build steps should be correct.
Compile again. If you receive some 'unresolved external' errors, then you need to make another change to the project file.


''Running as Debug''
Right-click on on the server project and choose Properties. Navigate to ''Configuration Properties > Linker > Input'' and add <code>user32.lib</code> to the first setting. It should now read <code>winmm.lib user32.lib</code>. Repeat this for the client.


Either run the mod using run_mod.bat, or add the following to STEAM's command line arguments for your mod.
If you still get errors, try adding <code>kernel32.lib</code> as well.
 
== intrin.h errors ==
 
This is a bug with VC++2005 that you may encounter. To fix it, open <code>C:\Program Files\Microsoft Visual Studio 8\VC\include\intrin.h</code> and comment out lines 944 and 945. This fixes a contradiction between two VC++ header files and shouldn't cause any damage.
 
== Fixing the custom build step ==
 
:''This problem is fixed in the current [[SDK Beta]].''
 
The project files created by the mod wizard won't put your compiled DLLs in the right folders.
 
Open the client (and then server) properties and navigate to ''Configuration Properties -> Custom Build Step -> General''. Click the '...' button on the right of Command Line and paste in this:
 
if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
copy "$(TargetDir)"client.dll "c:\program files\steam\steamapps\SourceMods\MyMod\bin"
 
Then in Output, paste:
 
c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll
 
Remember to replace <code>MyMod</code> with the actual name of your mod, and to replace <code>client</code> with <code>server</code> when correcting that project.
 
You will need to perform the same fix for Release mode. Click the drop-down list in the top-left and choose it, then repeat the above. In addition, you will want to paste this if you intend to debug the release build:
 
if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
copy "$(TargetDir)"client.pdb "c:\program files\steam\steamapps\SourceMods\MyMod\bin"
 
If you do this, add the PDB file to Output as well.
 
== Running your mod ==
 
Remember to run with -allowdebug if you've got debug builds!


-allowdebug -developer 2 -debug
{{clr}}
== See also ==
== See also ==
* [[Compiling under VS2008]]
* [[Microsoft Visual Studio 6.0 Usage]]
* [[Microsoft Visual Studio 6.0 Usage]]
* [[Compiling under VS2008]]
* [[Compiling under VS2002]]
* [[Compiling under VS2002]]
* [[Compiling under VS2005/Older SDK]]
* [[Compiling under VS2005/Older SDK]]

Revision as of 12:49, 17 March 2009

Visual Studio 2005 is the officially-supported IDE of the Source SDK, and if all is well you won't need to do anything special to use it. If you're using Visual C++ 2005 Express or if something is awry however, this page should get you up and running. It assumes you are compiling the Orange Box source code.

Installing

If you don't already have VS2005, you can download the free C++ Express version from Microsoft. After it has installed, run Windows Update to patch it. Do this twice if you are using Windows Vista to catch a compatibility update.

Windows SDK

If you're using Visual C++ Express 2005 you will need to install the Windows SDK to compile the game client.

It doesn't matter which version you download; this one does the job well enough. Don't worry that it talks about Vista - it also covers XP. Windows 2000 users however need to download the older Platform SDK instead.

Note.pngNote:You only need the "headers and libraries" component, about half-way through the list that the installer will present. They're about a 20MB download...the complete SDK is over 2GB!
Note.pngNote:If you are installing on a 64bit OS, remember that it is still the 32bit (x86) libraries that you want. They aren't selected by default.

Once you have the Windows SDK installed, try compiling. If you encounter errors about not being able to find winerror.h then you need to manually tell Visual C++ where the SDK is located.

To do this, navigate to Tools > Options > Projects and Solutions > VC++ Directories. Add the Windows SDK's \bin folder to the list. It will probably be:

C:\Program Files\Microsoft SDKs\Windows\v6.1\bin

Click on the drop-down list that currently says "Executable files". You now need to add the \include folder to the 'Includes' list and the \lib folder to the 'Library' list.

Tip.pngTip:You'll need to go through this process if you want to use the DirectX SDK too.
Adding the Windows SDK's includes.

Add dependencies

Compile again. If you receive some 'unresolved external' errors, then you need to make another change to the project file.

Right-click on on the server project and choose Properties. Navigate to Configuration Properties > Linker > Input and add user32.lib to the first setting. It should now read winmm.lib user32.lib. Repeat this for the client.

If you still get errors, try adding kernel32.lib as well.

intrin.h errors

This is a bug with VC++2005 that you may encounter. To fix it, open C:\Program Files\Microsoft Visual Studio 8\VC\include\intrin.h and comment out lines 944 and 945. This fixes a contradiction between two VC++ header files and shouldn't cause any damage.

Fixing the custom build step

This problem is fixed in the current SDK Beta.

The project files created by the mod wizard won't put your compiled DLLs in the right folders.

Open the client (and then server) properties and navigate to Configuration Properties -> Custom Build Step -> General. Click the '...' button on the right of Command Line and paste in this:

if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
copy "$(TargetDir)"client.dll "c:\program files\steam\steamapps\SourceMods\MyMod\bin"

Then in Output, paste:

c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll

Remember to replace MyMod with the actual name of your mod, and to replace client with server when correcting that project.

You will need to perform the same fix for Release mode. Click the drop-down list in the top-left and choose it, then repeat the above. In addition, you will want to paste this if you intend to debug the release build:

if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
copy "$(TargetDir)"client.pdb "c:\program files\steam\steamapps\SourceMods\MyMod\bin"

If you do this, add the PDB file to Output as well.

Running your mod

Remember to run with -allowdebug if you've got debug builds!

See also

Template:Otherlang:en Template:Otherlang:en:de