Compiling under VS2005: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
 
(49 intermediate revisions by 18 users not shown)
Line 1: Line 1:
{{LanguageBar}}
{{TabsBar|main=Visual Studio}}
{{Outdated sdk|{{src07|4.1}}|newer-sdk-equivalent=[[Compiler choices]]}}
{{toc-right}}
{{toc-right}}


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.
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, you'll need to do some work to get it up and running. '''This page assumes you are compiling the latest Orange Box source code.'''
 
== Supported versions ==
* {{Srcsdk06|2}}
* {{Srcsdk07|2}}


== Installing ==
== Installing ==
Is it recommended to obtain the full Visual Studio 2005 Professional since it includes the Windows/Platform SDK.
Both VS2005 and VCE2005 is no longer supported by or officially available from Microsoft. User will need to obtain VCE2005 at [https://archive.org/details/mvs-2005-ee Internet Archive] (Mount the downloaded ISO and go to {{path|Visual C++ 2005 Express Edition}} folder, and move the {{code|VC.iso}} to any folder before mounting it and run setup.exe). Alternatively, users can also get VS2005 Professional [https://archive.org/details/en_vs_2005_cd here].
{{Note|On Windows 10 and later, Program Compatibility Assistant will pop-up when you trying to install (and run) Visual Studio/VCE 2005. You can ignore these but if the program doesnt run, try to disable Program Compatibility Assistant in Windows Services and then run VS2005 again.}}
After Visual Studio or VCE has been installed, it is recommended to install [[#Visual Studio 2005 SP1|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://web.archive.org/web/20121114020440/https://www.microsoft.com/en-us/download/details.aspx?id=7524 SP1 Vista Update] (Note that this update also applies to Win7 and later). Then run Windows Update to finish patching it. (If there are no updates for VS/VCE, try to enable '''"Receive updates for other Microsoft products'''". Also if you already installed everything above, there will be no updates.)


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.
=== Visual Studio 2005 SP1 ===
* [https://www.catalog.update.microsoft.com/Search.aspx?q=visual%20studio%202005 Get Visual Studio 2005 SP1]
** For Microsoft Visual Studio 2005 Standard, Professional, Team Editions, get '''Visual Studio 2005 Service Pack 1'''.
** For Microsoft Visual Studio 2005 Express Editions, get '''Visual Studio 2005 Express Editions Service Pack 1'''.
** For systems running Windows Vista, 7 and later, get the '''[https://web.archive.org/web/20121114020440/https://www.microsoft.com/en-us/download/details.aspx?id=7524 SP1 Vista]''' update (SP1 update must be installed first).
{{Note|Alternatively, you can use Windows Update (with '''"Receive updates for other Microsoft products'''" enabled), to get SP1.}}


== Windows SDK ==
== Windows SDK (Express Only) ==


If you're using Visual C++ Express 2005 you need to install the Windows SDK. (If you're using Visual Studio 2005 this has already been done for you.)
If you're using Visual C++ Express 2005 you need to install the Windows SDK.


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.


{{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!}}
Be warned that the Windows 7 SDK offered below is known to cause issues with Visual Studio 2010 SP1.


{{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.}}
<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.


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:
Windows 2000 users however should follow instructions in [[Compiling under VS2005/Older SDK|Older SDK]]


C:\Program Files\Microsoft SDKs\Windows\v6.1\bin
:''*: 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)''


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.
{{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!}}


{{tip|You'll need to go through a similar process if you've installed the DirectX SDK.}}
{{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.}}


[[Image:Vc2005 dirs.png|center|Adding the Windows SDK's includes.]]
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>.


Hit OK to return to the workspace. Now 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 in Release mode (choose it from the top-left drop-down list), then repeat both modes again for the client project.
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.


If you get "unresolved external" errors, try adding <code>kernel32.lib</code> as well.
[[File:Vc2005 dirs.png|center|Adding the Windows SDK's includes.]]


== intrin.h errors ==
{{tip|You'll need to go through a similar process if you've installed the DirectX SDK.}}


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.
== Open the Solution ==


== Fixing the custom build step ==
# Launch your copy of '''Microsoft Visual Studio'''.
# 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.


:''This problem is fixed in the current [[SDK Beta]].''
== LNK2019 Errors ==


The project files created by the mod wizard won't put your compiled DLLs in the right folders.
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).


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 replace everything there with this:
If you get "unresolved external" errors, try adding <code>advapi32.lib</code> and <code>kernel32.lib</code> as well.


if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll"
== <code>error C2733 referring to winnt.h or intrin.h</code> ==
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:
You may receive an error such as: "<code>error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed</code>"


c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.dll
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.


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.
For '''Express users ONLY''', since you have no choice but to install an external SDK, [https://web.archive.org/web/20200722172850/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.  


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:
{{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.}}


if exist "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
Here are the previous instructions given:
attrib -r "c:\program files\steam\steamapps\SourceMods\MyMod\bin\client.pdb"
:''"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."''
copy "$(TargetDir)"client.pdb "c:\program files\steam\steamapps\SourceMods\MyMod\bin"


If you do this, add the PDB file to Output as well.
''You put the same download before in Windows SDK Express Only. : MatiasKiller21 [https://developer.valvesoftware.com/wiki/User:MatiasKiller21] : July 01 2015.''


== Running your mod ==
== Running Your Mod ==


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


== See also ==
== See also ==
 
* For other versions of Visual Studio, see the tab above.
* [[Compiling under VS2008]]
* [[Microsoft Visual Studio 6.0 Usage]]
* [[Compiling under VS2002]]
* [[Compiling under VS2005/Older SDK]]
* [[Compiling under VS2005/Older SDK]]
 
* [[My First Mod]]
{{otherlang:en}}
{{otherlang:en:de|Compiling_under_VS2005:de}}


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

Latest revision as of 02:32, 3 October 2024

English (en)Deutsch (de)Русский (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.

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, you'll need to do some work to get it up and running. This page assumes you are compiling the latest Orange Box source code.

Supported versions

Installing

Is it recommended to obtain the full Visual Studio 2005 Professional since it includes the Windows/Platform SDK. Both VS2005 and VCE2005 is no longer supported by or officially available from Microsoft. User will need to obtain VCE2005 at Internet Archive (Mount the downloaded ISO and go to 🖿Visual C++ 2005 Express Edition folder, and move the VC.iso to any folder before mounting it and run setup.exe). Alternatively, users can also get VS2005 Professional here.

Note.pngNote:On Windows 10 and later, Program Compatibility Assistant will pop-up when you trying to install (and run) Visual Studio/VCE 2005. You can ignore these but if the program doesnt run, try to disable Program Compatibility Assistant in Windows Services and then run VS2005 again.

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 SP1 Vista Update (Note that this update also applies to Win7 and later). Then run Windows Update to finish patching it. (If there are no updates for VS/VCE, try to enable "Receive updates for other Microsoft products". Also if you already installed everything above, there will be no updates.)

Visual Studio 2005 SP1

  • Get Visual Studio 2005 SP1
    • For Microsoft Visual Studio 2005 Standard, Professional, Team Editions, get Visual Studio 2005 Service Pack 1.
    • For Microsoft Visual Studio 2005 Express Editions, get Visual Studio 2005 Express Editions Service Pack 1.
    • For systems running Windows Vista, 7 and later, get the SP1 Vista update (SP1 update must be installed first).
Note.pngNote:Alternatively, you can use Windows Update (with "Receive updates for other Microsoft products" enabled), to get SP1.

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.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, 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.pngTip: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 advapi32.lib and 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.pngWarning: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