Garry's Mod Wiki

Revision Difference

Setting_Visual_Studio_Up_for_Making_Binary_Modules#561071

<cat>Dev</cat>⤶ <cat>Dev.Modules</cat>⤶ <deprecated>This page was made for old version of gmod-module-base. Use <page>Creating Binary Modules: CMake</page> or <page>Creating Binary Modules: Premake</page></deprecated>. # Basic Understanding of C++ Before you continue you should already have a basic understanding of C++. I recommend reading up tutorials found [here](http://www.cplusplus.com). # Downloading your IDE First of all you want to download [Visual Studio 2010](http://www.microsoft.com/visualstudio/eng/products/visual-studio-2010-express). It's all personal preference what IDE you use. You can use 2012 or a 2013; you don't even have to use Visual Studio. Visual Studio 2010 is what I'm using for this tutorial, so I recommend using it if it's your first module. # Garry's Mod Lua Headers The headers you need and an example are [available here](https://github.com/Facepunch/gmod-module-base/tree/development). You'll need to click "Download Zip" found to the right of the page. From there extract the include folder somewhere, I recommend somewhere like "C:\Garry's Mod Lua Headers" or "C:\Users\<username>\Documents\Garry's Mod Lua Headers" # Creating a New Project Open your IDE, in this case Visual Studio 2010, then select new project. Select "Win32" then click "OK". From here select Win32 Project make the name whatever you want. I recommend something like gm_test for your first module. <image src="New_Project_Info.png"/> There should be a Win32 Application Wizard opened, click next then under "Application type" select DLL. Then check the box "Empty project", finally click "Finish". <image src="Win32_Application_Wizard.png"/> Congratulations! You now have an empty project. # Setting Up the Project Now that you have your empty project you need to set up some directories, add some files and set some properties. Firstly you need to right click the folder "Source Files" and then click "Add new item...". <image src="Add_new_item.png"/> From inside here click "C++ file (.cpp)", name it "main". <image src="Add_new_main.png"/> The the next thing you must do is set it to release mode. At the top, near the green play looking button, you should see "Debug" then "Win32". Open the drop down menu on "Debug" and set it to "Release". <image src="Set_to_release.png"/> ## Properties Now right click your project, in this case "gm_test", and then click "Properties". <image src="Visual_Studios_properties.png"/> ### Configuration Properties Go into "Configuration Properties" and under "Project Defaults" then go to "Character Set" and select "Use Multi-Byte Character Set". This is helpful with strings so you don't have to use useless stuff. Next in "Configuration Properties" make the "Target Name" something like "gmcl_test_win32" so that you can just drag and drop it into your lua/bin folder without having to rename it after every compile. <image src="Visual_Studios_configuration_properties.png"/> ### C/C++ Now that that's out of the way, click the "C/C++" category and then select "Additional Include Directories", in the drop down menu, select "<Edit...>". <image src="Visual_Studios_ccplusplus_properties.png"/> From inside this menu select the little folder icon this should make a new blank entry. Double click it then select the "..." button. <image src="Visual_Studios_aditional_include_directories.png"/> Now go to where you saved your headers to, in this case "C:\Garry's Mod Headers\" from here go to "include\GarrysMod\Lua" then click "Select folder". Your full path should be something along the lines of "C:\Garry's Mod Headers\include\GarrysMod\Lua". <image src="Visual_Studios_aditional_folder_select.png"/> Click OK, then Click Apply, then Click OK again. You're almost ready to compile your first module. # Main.cpp Open up main.cpp and add the following code: ``` #define GMMODULE #include "Interface.h" // Called when the module opens GMOD_MODULE_OPEN() { return 0; } // Called when the module closes GMOD_MODULE_CLOSE() { return 0; } ``` # Compiling If done correctly, you should be able to compile it. Right click your project and click "Rebuild", note that it's a good habit to always select rebuild instead of build. <image src="Visual_Studios_rebuild.png"/>