Difference between revisions of "Compiling under VS2005"

From Valve Developer Community
Jump to: navigation, search
(Requirements: Fixed links.)
 
(63 intermediate revisions by 31 users not shown)
Line 1: Line 1:
{|align=right
+
{{otherlang2
|__TOC__
+
| de = Compiling_under_VS2005:de
|}
+
| ru = Compiling_under_VS2005:ru
 +
|zh-cn = Compiling_under_VS2005:zh-cn
 +
}}
  
 +
{{toc-right}}
  
== Introduction ==
+
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, read on to get it up and running. '''This page assumes you are compiling the latest Orange Box source code.'''
  
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 the _2005.sln files. Compiling a _2003.sln 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]].
+
== Installing ==
  
== What's Working ==
+
Is it recommended to obtain the full Visual Studio 2005 Professional since it includes the Windows/Platform SDK.
 +
VCE2005 is no longer supported by or officially available from Microsoft. [http://download.microsoft.com/download/A/9/1/A91D6B2B-A798-47DF-9C7E-A97854B7DD18/VC.iso It can still be downloaded from Microsoft] Through it might disappear sometime soon!
  
''SP''
+
After Visual Studio or VCE has been installed, it is recommended to install [https://support.microsoft.com/en-us/help/928957 SP1] ([https://blogs.msdn.microsoft.com/heaths/2006/10/06/vs-2005-sp1-requires-a-lot-of-disk-space/ Be warned that it has a install bug of consuming a lot of space!])and [https://www.microsoft.com/en-us/download/details.aspx?id=7524 Vista Update for SP1]. Then run Windows Update to finish patching it. (If there are no updates for VS/VCE, don't worry)
*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 fullfilled)
 
*Release - hl - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fullfilled)
 
  
''MP''
+
== Windows SDK (Express Only) ==
*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 fullfilled)
 
*Release - hl - V C++ Express: '''working''' & playable (after [[Compiling_under_VS2005#Requirements|requirements]] are fullfilled)
 
  
== Requirements ==
+
If you're using Visual C++ Express 2005 you need to install the Windows SDK.
  
Necessary steps are needed to enable compiling with the Visual Studio C++ 2005 Express Edition:
 
  
''Files required''
+
Be warned that the Windows 7 SDK offered below is known to cause issues with Visual Studio 2010 SP1.
  
*[http://msdn.microsoft.com/directx/sdk/ MS DirectX SDK]
+
<strike>It doesn't matter which version you download</strike>*; [http://web.archive.org/web/20161108080358/http://www.microsoft.com/en-us/download/details.aspx?id=24826 this one does the job] well enough.  Don't worry that it talks about Vista - it also covers XP.
*[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
 
  
''Setup''
+
Windows 2000 users however should follow instructions in [[Compiling under VS2005/Older SDK|Older SDK]]
  
Go to Tools - Options: Projects and Solutions - VC++ Directories
+
:''*: I'm pretty sure it does matter which version you download. See [[#error C2733 referring to winnt.h or intrin.h|below]]. -- [[User:Neverender|Neverender]] 17:26, 6 October 2012 (PDT)''
  
* In the upper right drop down box, select "Executable files" and add "...\Microsoft Platform SDK\Bin" (replace with the correct path)
+
{{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!}}
  
* Then select "Include files" and add "...\Microsoft Platform SDK\Include" and "...\Microsoft DirectX SDK (December 2005)\Include"
+
{{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.}}
  
* Then select "Library files" and add "...\Microsoft Platform SDK\Lib" and "...\Microsoft DirectX SDK (February 2007)\Lib\x86"
+
Once you have the Windows SDK installed, you need to 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 <code>\bin</code> folder to the list. The default location is <code>C:\Program Files\Microsoft SDKs\Windows\v6.1\bin</code>.
  
* Finally, in the Solution Explorer right click 'client_hl2', and select Properties, then:
+
Click on the drop-down list that ''currently'' says "Executable files". You need to add the <code>\include</code> folder to the 'Includes' list and the <code>\lib</code> folder to the 'Library' list.
:* In the client_hl2 properties window, navigate to Linker -> Input
 
:* 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, and type ' user32.lib ' without the quotes.
 
:* Repeat these steps for 'server_hl2'
 
  
== Possible Problems ==
+
[[Image:Vc2005 dirs.png|center|Adding the Windows SDK's includes.]]
''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 gpGlobals, with an access violation at memory location 0x0000038.
+
{{tip|You'll need to go through a similar process if you've installed the DirectX SDK.}}
{{note|Only follow this step if you encounter this issue. Often, it is not required}}
 
  
Right-click on the client_sdk project, and go to Configuration Properties -> Custom Build Step -> General. Set Command Line to:
+
== Open the solution ==
  
if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll" attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
+
# Launch your copy of '''Microsoft Visual Studio'''.
if exist "$(TargetDir)"client.dll copy "$(TargetDir)"client.dll "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
+
# Select '''File-&gt;Open-&gt;Project/Solution''' from the menu and open the '''Game_Episodic-2005.sln''' solution located in your mod's <code>src</code> directory, select the one that matches your version of '''Microsoft Visual Studio'''If you selected mod from scratch, "Scratch" will appear there instead.
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:
+
== LNK2019 errors ==
  
"c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll";"c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
+
If you receive these errors, right-click on the client and server projects in turn and select the last option in the menu, Properties. Then navigate to ''Configuration properties > Linker > Input'' and make the first item, "Additional Dependencies", read <code>winmm.lib user32.lib</code>. Make sure you've done this for both Debug and Release mode (switch between them in the top left of the Properties window).
  
(In both, replace "MyMod" with your mod's directory.)
+
If you get "unresolved external" errors, try adding <code>kernel32.lib</code> as well.
  
Click "Apply" (you *will* lose your changes if you forget this). 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 server_sdk's custom build steps should be correct.
+
== error C2733 referring to winnt.h or intrin.h ==
  
== Related Articles ==
+
You may receive an error such as: "<code>error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed</code>"
*[[Microsoft Visual Studio 6.0 Usage]]
 
*[[Compiling under VS2008]]
 
*[[Compiling under VS2002]]
 
*[[Compiling under VS2005/Older SDK]]
 
  
{{otherlang:en}} {{otherlang:en:de|Compiling_under_VS2005:de}}
+
This error is caused by trying to build against an incompatible version of the Windows SDK/Platform SDK. When using the full version of Visual C++ 2005, your Visual C++ directories (in "Options") should not refer to any newer external SDK include/lib paths; only the ones included with the Visual C++ 2005 installation by default. Reverting the "VC++ Directories" settings to default should solve this problem.
[[Category:Tutorials]] [[Category:Programming]]
+
 
 +
For '''Express users ONLY''', since you have no choice but to install an external SDK, [http://www.microsoft.com/en-us/download/details.aspx?id=6510 this version] may help. If '''all else fails''', some users have resorted to working around this problem by editing their SDK headers.
 +
 
 +
{{warning|Editing vendor provided header files is a '''BAD''' idea. This is a hack of last resort; however, by using Visual C++ Express, you are already working in an unsupported configuration.}}
 +
 
 +
Here are the previous instructions given:
 +
:''"Open <code>C:\Program Files\Microsoft Visual Studio 8\VC\include\intrin.h</code> and comment out lines 944 and 945. If you continue to receive errors, comment out the referenced lines (typically 913 and 912) and recompile."''
 +
 
 +
<i>You put the same download before in Windows SDK Express Only. : MatiasKiller21 [https://developer.valvesoftware.com/wiki/User:MatiasKiller21] : July 01 2015.</i>
 +
 
 +
== Running your mod ==
 +
 
 +
Remember to run with -allowdebug if you've got debug builds!
 +
 
 +
== See also ==
 +
 
 +
* [[Compiling under VS2010]]
 +
* [[Compiling under VS2008]]
 +
* [[Compiling under VS2002]]
 +
* [[Compiling under VS2005/Older SDK]]
 +
* [[My First Mod]]
 +
 
 +
[[Category:Tutorials]]
 +
[[Category:Programming]]
 +
[[Category:Source SDK FAQ]]

Latest revision as of 06:19, 7 March 2020

Deutsch Русский 简体中文

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, read on to get it up and running. This page assumes you are compiling the latest Orange Box source code.

Installing

Is it recommended to obtain the full Visual Studio 2005 Professional since it includes the Windows/Platform SDK. VCE2005 is no longer supported by or officially available from Microsoft. It can still be downloaded from Microsoft Through it might disappear sometime soon!

After Visual Studio or VCE has been installed, it is recommended to install SP1 (Be warned that it has a install bug of consuming a lot of space!)and Vista Update for SP1. Then run Windows Update to finish patching it. (If there are no updates for VS/VCE, don't worry)

Windows SDK (Express Only)

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


Be warned that the Windows 7 SDK offered below is known to cause issues with Visual Studio 2010 SP1.

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 should follow instructions in Older SDK

*: I'm pretty sure it does matter which version you download. See below. -- Neverender 17:26, 6 October 2012 (PDT)
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!
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.

Once you have the Windows SDK installed, you need to 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. The default location is C:\Program Files\Microsoft SDKs\Windows\v6.1\bin.

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

Adding the Windows SDK's includes.
Tip:You'll need to go through a similar process if you've installed the DirectX SDK.

Open the solution

  1. Launch your copy of Microsoft Visual Studio.
  2. Select File->Open->Project/Solution from the menu and open the Game_Episodic-2005.sln solution located in your mod's src directory, select the one that matches your version of Microsoft Visual Studio. If you selected mod from scratch, "Scratch" will appear there instead.

LNK2019 errors

If you receive these errors, right-click on the client and server projects in turn and select the last option in the menu, Properties. Then navigate to Configuration properties > Linker > Input and make the first item, "Additional Dependencies", read winmm.lib user32.lib. Make sure you've done this for both Debug and Release mode (switch between them in the top left of the Properties window).

If you get "unresolved external" errors, try adding kernel32.lib as well.

error C2733 referring to winnt.h or intrin.h

You may receive an error such as: "error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed"

This error is caused by trying to build against an incompatible version of the Windows SDK/Platform SDK. When using the full version of Visual C++ 2005, your Visual C++ directories (in "Options") should not refer to any newer external SDK include/lib paths; only the ones included with the Visual C++ 2005 installation by default. Reverting the "VC++ Directories" settings to default should solve this problem.

For Express users ONLY, since you have no choice but to install an external SDK, this version may help. If all else fails, some users have resorted to working around this problem by editing their SDK headers.

Warning: Editing vendor provided header files is a BAD idea. This is a hack of last resort; however, by using Visual C++ Express, you are already working in an unsupported configuration.

Here are the previous instructions given:

"Open C:\Program Files\Microsoft Visual Studio 8\VC\include\intrin.h and comment out lines 944 and 945. If you continue to receive errors, comment out the referenced lines (typically 913 and 912) and recompile."

You put the same download before in Windows SDK Express Only. : MatiasKiller21 [1] : July 01 2015.

Running your mod

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

See also