Compiling under VS2010: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(corrections and cleanup)
Line 1: Line 1:
== Compiling with Visual Studio C++ 2010 ==
'''Visual Studio 2010''' has a lot of great features, and can be used with the Source SDK fairly easily. It will be released on April 11 (April 12 for the free C++ Express edition), but can be used today in Release Candidate form.


Visual Studio 2010 has a lot of great features, unfortunately there's not a lot of support for it yet (it is in beta after all). It takes a fair amount of tweaking to get it working, and '''your debug DLLs compiled from Visual Studio 2010 will not work - you MUST use release DLLs'''.
{{note|The earlier beta releases of VS2010 can't properly compile debug DLLs.}}
 
== Opening Your Mod ==
 
Once you've [http://developer.valvesoftware.com/wiki/My_First_Mod#Create_the_project created your mod], open up Visual Studio and go to '''File -> Open -> Project\Solution'''. Navigate to your mod's source directory and open up '''Game_Episodic-2005.sln'''. It will ask if you want to convert it, do so. If it's a new mod don't bother choosing the back it up option.


== Fixing Compilation ==
== Fixing Compilation ==


As mentioned above, '''YOU CANNOT USE DEBUG DLLS''' with Visual Studio 2010. They will compile but the game will refuse to load them. This means you'll be doing all your work in Release configuration. Up near the top of your Visual Studio window you'll see a drop down box saying Debug, change that to Release. Now to get your solution to compile you'll have to go through a few steps.
# Follow the instructions [[Compiling under VS2008#Fix debug compilation|for fixing debug compiles in VS2008]], which apply here as well.
# Right click on the client and server projects in VS and go to ''Properties > Configuration > General''. Change ''Target Name'' to ''client'' and ''server'' respectively.


# Follow the Fix Debug Compilation step from [http://developer.valvesoftware.com/wiki/Compiling_under_VS2008#Fix_debug_compilation this tutorial].
== Fixing Warnings ==
# Right click on '''Client_Episodic''' and go to '''Properties'''. Go to '''Configuration Properties->General''' and change '''Target Name''' to '''client'''.
# Right click on '''Server_Episodic''' and go to '''Properties'''. Go to '''Configuration Properties->General''' and change '''Target Name''' to '''server'''.
# Right click on '''Client_Episodic''' and go to '''Properties'''. Go to '''Custom Build Step'''. If you click on '''Command Line''' a drop down arrow will appear. Click that and go to '''<Edit...>'''. Make the appropriate changes to the following code based on your mod location/name and insert them here:
 
<code>
if exist "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.dll" attrib -r "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.dll"
if exist "$(TargetDir)client.dll" copy "$(TargetDir)client.dll" "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin"
if exist "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.pdb" attrib -r "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.pdb"
if exist "$(TargetDir)client.pdb" copy "$(TargetDir)client.pdb" "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin"
</code>


<ol start="5">
You're going to be stuck with at least one warning during compilation, but you can get rid of some of them. Open these files in your client project and move <code>#include "cbase.h"</code> up to the first line:
<li>
Right click on '''Server_Episodic''' and go to '''Properties'''. Go to '''Custom Build Step'''. If you click on '''Command Line''' a drop down arrow will appear. Click that and go to '''<Edit...>'''. Make the appropriate changes to the following code based on your mod location/name and insert them here:
</li>
</ol>


<code>
if exist "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\server.dll" attrib -r "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\server.dll"
if exist "$(TargetDir)server.dll" copy "$(TargetDir)client.dll" "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin"
if exist "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.pdb" attrib -r "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin\client.pdb"
if exist "$(TargetDir)client.pdb" copy "$(TargetDir)client.pdb" "c:\program files (x86)\steam\steamapps\SourceMods\<MODNAME>\bin"
</code>
There are times when Visual Studio won't copy your DLLs and PDBs over to the '''...\SourceMods\<MODNAME>\bin\''' directory even after it's compiled changes in your code. If this happens just delete the contents of '''...\SourceMods\<MODNAME>\bin\''' and rebuild your solution, or just move them yourself. Either way works.
== Fixing Warnings ==
You're going to be stuck with at least one warning during compilation, but you can get rid of some of them. Open the following files in your '''Client_Episodic''' project ''(Source Files -> HL2 DLL)'' and move '''#include "cbase.h"''' up to the top of the includes:
# hud_locator.cpp
# hud_locator.cpp
# hud_credits.cpp
# hud_credits.cpp
# hud_flashlight.cpp
# hud_flashlight.cpp


Next highlight both '''Client_Episodic''' and '''Server_Episodic''' from the main window, right click and go to '''Properties'''.  Go to '''Configuration Properties->General''' and ensure that your configuration is set to release in the drop down window at the top. Change '''.\Release\''' to '''Release\''' (remove the .\) Click OK.
You may also want to go to ''Configuration Properties->General'' for both projects and change the ''Intermediate Directory'' from <code>.\Release\</code> to <code>Release\</code>, removing the <code>.\</code>. (That this produces a warning is a bug that should be fixed in VS2010's final release.)
 
 


== Running Your Mod ==
== See also ==


At this point you can continue from [http://developer.valvesoftware.com/wiki/Launching_from_Visual_Studio here] then launch your mod through Visual Studio.
* [http://www.microsoft.com/visualstudio/en-us/ Visual Studio 2010]
* [[Launching from Visual Studio]]


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

Revision as of 10:45, 14 March 2010

Visual Studio 2010 has a lot of great features, and can be used with the Source SDK fairly easily. It will be released on April 11 (April 12 for the free C++ Express edition), but can be used today in Release Candidate form.

Note.pngNote:The earlier beta releases of VS2010 can't properly compile debug DLLs.

Fixing Compilation

  1. Follow the instructions for fixing debug compiles in VS2008, which apply here as well.
  2. Right click on the client and server projects in VS and go to Properties > Configuration > General. Change Target Name to client and server respectively.

Fixing Warnings

You're going to be stuck with at least one warning during compilation, but you can get rid of some of them. Open these files in your client project and move #include "cbase.h" up to the first line:

  1. hud_locator.cpp
  2. hud_credits.cpp
  3. hud_flashlight.cpp

You may also want to go to Configuration Properties->General for both projects and change the Intermediate Directory from .\Release\ to Release\, removing the .\. (That this produces a warning is a bug that should be fixed in VS2010's final release.)

See also