Compiling under VS2005: Difference between revisions

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


Previously, there were substantial difficulties in successfully compiling a Source mod under Visual Studio 2005. When attempting to compile, VS threw a tremendous number of warnings and errors. These difficulties are categorized below; however, as of [[Source_SDK_Release_Notes|recently]] Theres a new code base and project files avalible for 2005. Tests so far indicate positive results with no errors encountered on any code base under the offical full release of VS2005. More community testing is underway but this page may most likely soon become uneeded.
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.'''


== Update ==
== Supported versions ==
* {{Srcsdk06|2}}
* {{Srcsdk07|2}}


Whats working now with the new [[Source_SDK_Release_Notes|2005.sln]] file:
== 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].


''SP''
{{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.}}
*Release - client - VS Studio: '''working'''
*Release - hl - VS Studio: '''working'''
*Release - client - V C++ Express: '''working''' & playable
*Release - hl - V C++ Express: '''working''' & playable


''MP''
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.)
*Release - client - VS Studio: '''working'''
*Release - hl - VS Studio: '''working'''
*Release - client - V C++ Express: to be tested
*Release - hl - V C++ Express: to be tested


== VS Express vs. VS Standard ==
=== 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.}}


Neither VS2005 Express nor VS 2005 does work with the Source SDK at the moment but Valve is currently working on it. For the status on this see [http://developer.valvesoftware.com/cgi-bin/bugzilla/show_bug.cgi?id=1 bugzilla].
== Windows SDK (Express Only) ==


In the past Microsoft planned to give free express versions for hobbyists only for 1 year. But in April they announced in a [http://www.microsoft.com/presspass/press/2006/apr06/04-19VSExpressFreePR.mspx press release] that it will remain free.
If you're using Visual C++ Express 2005 you need to install the Windows SDK.


== Introductions ==
First, there's a list of what has been tested and is working with this tutorial, or which is not. Separated in SP, MP and ''from scratch'' source code.


Also, there are the requirements, which are things that are needed besides the Source SDK and MS Visual, and how to set them up.
Be warned that the Windows 7 SDK offered below is known to cause issues with Visual Studio 2010 SP1.


Next comes the error fixing. A general, and then separated into ''Release'' and ''Debug'' building.
<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.


ErrorFixes will be stated as: file(line number)
Windows 2000 users however should follow instructions in [[Compiling under VS2005/Older SDK|Older SDK]]
and how the new line looks like


===List of Compile Time Errors and Warnings===
:''*: 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)''
[http://www.priyajeet.com/web/cache/Everythingsdk.xls Errors/Warnings in Excel Spreadsheet Format]
<br>All the errors and warning got from compileing the Everything_SDK.sln under Visual Studio 2005 with the latest Windows SDK and Directx SDK.
Majority errors are due to scope resolutions.
Majority warnings are due to usage of "legacy" C++ functions.


===What's Working?===
{{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!}}


Here's a list of what is tested and working:
{{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.}}


'''SP:'''
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>.
*Release - client - VS Studio: '''working''' but '''not playable''' -
*Release - hl - VS Studio: '''working''' but '''not playable''' -
*Debug - client - VS Studio: '''working''' but '''not playable''' - 826 warnings
*Debug - hl - VS Studio: '''working''' but '''not playable''' - 1148 warnings


*Release - client - V C++ Express: '''working''' but '''not playable''' - 33 warnings
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.
*Release - hl - V C++ Express: '''working''' but '''not playable''' - 42 warnings
*Debug - client - V C++ Express: not tested yet
*Debug - hl - V C++ Express: not tested yet


'''MP:'''
[[File:Vc2005 dirs.png|center|Adding the Windows SDK's includes.]]
*Release - client - V C++ Express: '''working''' & playable - 33 warnings
*Release - hl - V C++ Express: '''working''' & playable - 42 warnings
*Release - hl - client - Visual Studio 2005 Working and Playable 0 errors; 2 warnings for hl 3 warnings for client ([http://sean.cyberwang.net/files/HL2MP.diff Patch File For Code Changes])
*none tested yet


'''scratch:'''
{{tip|You'll need to go through a similar process if you've installed the DirectX SDK.}}
*Release - client - V C++ Express: '''working''' - 33 warnings
*Release - hl - V C++ Express: '''working''' - 42 warnings
*not tested yet


=== Requirements (other SDKs and Setup of those) ===
== Open the Solution ==


steps till being able to compile with V C++ 05 (Express):
# 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.


required:
== LNK2019 Errors ==


*[http://msdn.microsoft.com/directx/sdk/ MS DirectX SDK]
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).
*[http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en MS Platform SDK]


If you get "unresolved external" errors, try adding <code>advapi32.lib</code> and <code>kernel32.lib</code> as well.


''setup''
== <code>error C2733 referring to winnt.h or intrin.h</code> ==


Tools - Options: Projects and Solutions - VC++ Directories
You may receive an error such as: "<code>error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed</code>"


upper right select "executable files" and enter "...\Microsoft Platform SDK\Bin" (replace the correct path)
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.


"include files" --> "...\Microsoft Platform SDK\Include" and "...\Microsoft DirectX SDK (December 2005)\Include"
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.


"libary files" --> "...\Microsoft Platform SDK\Lib" & "...\Microsoft DirectX SDK (December 2005)\Lib\x86"
{{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.}}


== Project 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."''


=== Disabling Deprecated Declaration Warnings ===
''You put the same download before in Windows SDK Express Only. : MatiasKiller21 [https://developer.valvesoftware.com/wiki/User:MatiasKiller21] : July 01 2015.''


This fix will disable the deprecated declaration warnings, which indeed is only a warning.
== Running Your Mod ==


It warns that the used functions are old ones and there are new, more secure versions but this can be ignored.
Remember to run with -allowdebug if you've got debug builds!


..\public\tier0\'''dbg.h'''
== See also ==
* For other versions of Visual Studio, see the tab above.
* [[Compiling under VS2005/Older SDK]]
* [[My First Mod]]


add
[[Category:Tutorials]]
#pragma warning(disable : 4996)
[[Category:Programming]]
after #pragma once (new line) to disable old, unsecure functions warning.
[[Category:Source SDK FAQ]]
 
[[Category:Source 2006]]
=== Disabling /COMMENT Warning ===
[[Category:Source 2007]]
 
This fix will remove comments from debug obj. since the comment doesnt work in VS2005 it wont be put in anyway.
 
Find:
 
#ifdef _WIN32
  #ifdef _DEBUG
#pragma comment(compiler)
#pragma comment(exestr,"*** DEBUG file detected, Last Compile: " __DATE__ ", " __TIME__ " ***")
#endif
#endif
 
Replace With:
 
#ifdef _WIN32
#ifdef _DEBUG
//#pragma comment(compiler)
//#pragma comment(exestr,"*** DEBUG file detected, Last Compile: " __DATE__ ", " __TIME__ " ***")
#endif
#endif
 
=== wchar_t Linker errors ===
 
Linker errors with wchar_t as values:
 
Client->;Properties->C/C++->Language
and set Treat wchar_t as Built in Type to No.
 
This is because the Valve library vgui_control.lib is compiled with the option - Treat wchar_t as Built in Type - set to No so they need to be the same.
 
An alternative fix is to recompile vgui_control.lib with the option set to Yes - its found in src\vgui2\controls. Backing up vgui_control.lib is recommended - found in src\lib\public and recompile it with the option set to yes and then copy that to where the original lib was backed up.
 
== Code Changes ==
 
=== General ===
 
==== error C2065: 'i' : undeclared identifier ====
 
For the error C2065: 'i' : undeclared identifier, there are two ways to fix this.
For one after the other, rightclick client and hl,
go to C/C++ -> Language and set
Force Conformance in For Loop to No.
 
Alternatively fix would be adding the "int"-declaration into code.
 
=== Release-Compile configuration ===
 
<!--==== Downloadable fix set ====
There's also [http://clandooc.de/rotz/files/source/src_VS2005_Fix.zip a downloadable fixset], and unzip it in your "\src" folder. You will still have to fix the Project settings and linker, but no longer the file-fixes. This file only includes changes for Release-Compile.
 
 
----
----
 
 
Original file from Milbret's available here http://files.filefront.com/My_VS2005_Fixzip/;4996172;;/fileinfo.html
MyVS2005Fix]-->
 
==== Shared fixes ====
 
..\public\vstdlib\strtools.h(90):
inline char* Q_strrchr (const char *s, char c) { return strrchr( (char *)s, c ); }
 
..\public\vstdlib\strtools.h(93) zu
inline char* Q_strstr( const char *s1, const char *search ) { return strstr( (char *)s1, search ); }
 
..\cl_dll\hud_bitmapnumericdisplay.cpp(159)
if( bStart || digit > 0 || pos <= pow((float)10,numSigDigits-1) )
 
..\game_shared\baseentity_shared.cpp(251)
char *s = strchr( (char *)szKeyName, '#' );
 
..\tier1\KeyValues.cpp(800)
char *subStr = strchr((char *)keyName, '/');
 
=== Memoverride Linking Errors & Fixes: ===
 
memoverride.obj : error LNK2019: unresolved external symbol __aligned_malloc_base referenced in function __aligned_malloc
memoverride.obj : error LNK2019: unresolved external symbol __aligned_free_base referenced in function __aligned_free
 
Lines 405 - 430 in memoverride.cpp:
 
Before:
 
#if defined(_DEBUG) && _MSC_VER >= 1300
void    __cdecl _aligned_free_base(
        void *
        );
void *  __cdecl _aligned_malloc_base(
        size_t,
        size_t
        );
void * __cdecl _aligned_malloc(
        size_t size,
        size_t align
        )
{
    return _aligned_malloc_base(size, align);
}
void __cdecl _aligned_free(
        void *memblock
        )
{
    _aligned_free_base(memblock);
}
#endif
 
After:
 
#if defined(_DEBUG) && _MSC_VER >= 1300
void    __cdecl _aligned_free(
        void *
        );
void *  __cdecl _aligned_malloc(
        size_t,
        size_t
        );
void * __cdecl _aligned_malloc_base(
        size_t size,
        size_t align
        )
{
    return _aligned_malloc(size, align);
}
void __cdecl _aligned_free_base(
        void *memblock
        )
{
    _aligned_free(memblock);
}
#endif
 
==== Client fixes (client.dll) ====
 
''Linking Errors & Fixes:''
 
Added msvcrt.lib and user32.lib to Linker->Input->Additional Dependencies (separated each with a space(" "))
 
Added LIBC to Linker->Input->Ignore specific library
 
Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
 
==== HL fixes (server.dll) ====
 
'''..\dlls\vguiscreen.cpp(69)'''
char *s = strchr( (char *)szKeyName, '#' );
 
'''..\dlls\TemplateEntities.cpp(298)'''
int iMax = pow((double)10, (int)(strlen(ENTITYIO_FIXUP_STRING)-1)); // -1 for the &
 
===== Changing function-run to function-link (error C3867) =====
 
'''..\dlls\hl2_dll\weapon_rpg.cpp'''
 
* (150)  SetTouch( ''&CMissile::''MissileTouch );
* (153)  SetThink( &CMissile::IgniteThink );
* (256)  SetThink( &CMissile::SeekThink );
* (311)  SetThink( &CMissile::AugerThink );
* (435)  SetThink( &CMissile::SeekThink );
* (881)  SetTouch( &CAPCMissile::APCMissileTouch );
* (916)  SetThink( &CAPCMissile::BeginSeekThink );
* (925)  SetThink( &CAPCMissile::AugerStartThink );
* (938)  SetThink( &CMissile::AugerThink );
* (945)  SetThink( &CAPCMissile::ExplodeThink );
* (955)  SetThink( &CMissile::SeekThink );
* (2058) pLaserDot->SetContextThink( &CLaserDot::LaserThink, gpGlobals->curtime + 0.1f, g_pLaserDotThink );
 
'''..\dlls\hl2_dll\weapon_physcannon.cpp'''
* (2480) SetContextThink( &CWeaponPhysCannon::WaitForUpgradeThink, gpGlobals->curtime + 6.0f, s_pWaitForUpgradeContext );
* (2502) SetContextThink( &CWeaponPhysCannon::WaitForUpgradeThink, gpGlobals->curtime + 0.1f, s_pWaitForUpgradeContext );
 
'''..\dlls\hl2_dll\weapon_crossbow.cpp(324)'''
SetThink( &CBaseEntity::SUB_Remove );
 
'''..\dlls\hl2_dll\npc_BaseZombie.cpp(160) : fixed error C4430'''
static int s_iAngryZombies = 0;
 
'''..\dlls\baseentity.cpp(57): fixed error C3861: "tolower"'''
 
Line 57 should be ''#include "vphysics/friction.h"''. Insert ''#include <ctype.h>'' just after this line.
 
'''..\dlls\TemplateEntities.cpp(298)'''
int iMax = pow((long double)10, (int)(strlen(ENTITYIO_FIXUP_STRING)-1)); // -1 for the &
 
'''..\dlls\vguiscreen.cpp(69)'''
char *s = strchr((char *s)szKeyName, '#' );
 
==== Linking fixes ====
 
Added msvcrt.lib and user32.lib to Linker->Input->Additional Dependencies (separated each with a space(" "))
 
Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
 
=== Debug-Compile configuration ===
 
==== Linking Errors & Fixes ====
 
Added msvcrtd.lib and user32.lib Linker->Input->Additional Dependencies
 
Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
 
==== Client ====
 
...\public\tier0\memoverride.cpp line 405-430 (410-435 if you added functions above (release hl))
 
Remove "_base" from those functions and add it to return-var. Looks then like this:
 
*(406/411)
void    __cdecl _aligned_free(
*(410/415)
void *  __cdecl _aligned_malloc(
*(415/420)
void * __cdecl _aligned_malloc_base(
*(420/425)
    return _aligned_malloc(size, align);
*(423/428)
void __cdecl _aligned_free_base(
*(427/432)
    _aligned_free(memblock);
 
==== HL ====
 
...\dlls\ai_behavior_follow.cpp(2090)
//ASSERT_INVARIANT( sizeof(FollowerListIter_t) == sizeof(AI_FollowManagerInfoHandle_t) );
 
 
''Linking Errors & Fixes:''
 
Added user32.lib to Linker->Input->Additional Dependencies
 
Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
 
Added ''LIBCMTD'' to hl->Properties->Configuration Properties->Linker->Input->Ignore Specific Library
 
==Other Fixes==
 
{{note|In the end these were not needed...}}
 
=== STRDUP ===
The problem with strdup doesn't happen in debug mode since Valve overrides strdup with their own strdup func. The heap error only shows itself when using the debugger in release mode. I believe it's because strdup() in the C library that comes with 2005 express uses new() instead of malloc(). So when Valve frees the memory using free() it gives the error. Here's the fix I hope...
 
..\tier1\stringpool.cpp(73)
 
CHANGE
 
pszNew = strdup( pszValue );
TO
#ifndef _debug
pszNew = (char*) malloc(sizeof(char) * (strlen(pszValue) + 1)); // Use Valve's malloc instead of strdup
strcpy(pszNew, pszValue);
#else
pszNew = strdup( pszValue ); // Use Valve's debug strdup
#endif
 
 
..\cl_dll\c_baseflex.cpp(921)
 
CHANGE
 
g_flexcontroller[g_numflexcontrollers++] = strdup( szName );
 
TO
 
#ifndef _debug
g_flexcontroller[g_numflexcontrollers] = (char*) malloc(sizeof(char) * (strlen(szName) + 1)); //Use V's malloc instead of strdup
strcpy(g_flexcontroller[g_numflexcontrollers++], szName);
#else
g_flexcontroller[g_numflexcontrollers++] = strdup( szName ); //Use V's debug strdup
#endif
 
===BotPutInServer Linker Failures===
(worked for me, didn't have to do this with SP)
 
Various BotPutInServer lines will fail to link in DEBUG mode. Commenting the BotPutInServer lines out works just fine. This may have some negative affect on bots. I quite frankly have not looked into that stuff at all, other than to see that it breaks the build.
 
Fix:
A better way would be
adding hl2mp_bot_temp.h and hl2mp_bot_temp.cpp
to the HL project under the Source Files->HL2MP folder.
hl2mp_bot_temp.h and hl2mp_bot_temp.cpp can both be found in yourmod/src/dlls/hl2mp_dll folder.
 
=== Warnings ===
 
..\public\tier0\memoverride.cpp
*(107)
__declspec(restrict) __declspec(noalias) void *malloc( size_t nSize )
*(111)
__declspec(noalias) void free( void *pMem )
*(116)
__declspec(restrict) __declspec(noalias) void *realloc( void *pMem, size_t nSize )
*(121)
__declspec(restrict) __declspec(noalias) void *calloc( size_t nCount, size_t nElementSize )
 
*add this function to line 136 ''(i don't get what this is for???)''
void *_calloc_impl( size_t nCount, size_t nElementSize )
{
return calloc(nCount, nElementSize);
}
 
comment out _heap_init() and _heap_term(), means, ''(i don't get what this is for???)''
comment out everything from line 298 to line 303 (these lines are these lines if you added the function *_calloc_impl (which is 4 lines long) to line 136.
 
==Remaining Error List==
 
Here is a list of warnings not fixed yet. Though it's not defined whether they have to be or should be fixed or not.
 
===SP Debug Client===
 
..\public\tier0\commonmacros.h(29) : warning C4005: 'ARRAYSIZE': Makro-Neudefinition
''pathto''\microsoft platform sdk\include\winnt.h(950): Siehe vorherige Definition von 'ARRAYSIZE'
 
..\public\tier0\memoverride.cpp(413)(418)(418) : warning C4565 (I should be able to fix that, will check that again later...)
 
LINK : warning LNK4075: ignoring /INCREMENTAL due to /FORCE specification.
 
LONG LIST of .obj files, all with warning:
warning LNK4224: /COMMENT is no longer supported; ignored.
 
msvcrt.lib(MSVCR80.dll) : warning LNK4006: _free already defined in "memoverride.obj"; second definition ignored
 
.\cl_dll___Win32_HL2_Debug/client.dll : warning LNK4088: image being generated due to /FORCE option; image may not run.
 
===SP Debug hl===
 
..\public\tier0\memdbgon.h(83) : warning C4996: 'strcpy' (can stay like that...)
same for 'wcscpy' and 'strtok'
 
+some new double-definitions (LIBCMTD.lib, ...)
 
+the errors of SP Debug Client (LNK4224: /COMMENT, warning C4005: 'ARRAYSIZE')
 
== Related Articles ==
*[[Microsoft Visual Studio 6.0 Usage]]
*[[Compiling under VS2002]]
 
{{otherlang:en}} {{otherlang:en:de|Compiling_under_VS2005:de}}
[[Category:Tutorials]] [[Category:Programming]]

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