Post

C++ VS Project Setup

This guide will provide step-by-step instructions on how to create a Visual Studio C++ Solution and multiple Projects. The projects will be split between a game executable and a engine static library.

Update Visual Studio

Make sure you have Visual Studio Enterprise 2022 installed and that it is up to date.

  • Open Visual Studio and click Continue without code.
image
  • If there are any updates, the bell icon on the bottom right will be red.

    • If there is, click the bell icon and perform any updates by clicking Update on close.
image
image

Create Visual Studio Solution

  • Open Visual Studio and Create a new project.
image
  • Create an Empty Project.

    • To reduce project types listed, filter the projects by setting Language to C++ and Project type to Console.
image
  • Name your Project and Solution.

    • In this example, the Solution name is “CSC196”.

    • In this example, the Project name is “Game”.

  • Uncheck Place solution and project in the same directory

    • The Project needs to be in its own folder.

    • Click Create to create the project.

image
  • The Solution and Project will be created at the specified location.
image

Create Project Directory Structure

The Game Engine project will contain a variety of files and folders to build the game. Keeping the project organized is important as the project will grow in size and complexity.

  • Open the folder in Windows Explorer that the Solution is contained in.

    • A shortcut to go to the Solution directory is to right-click on the Solution and select Open Folder in File Explorer.
image
image
  • Add the following folders:

    • Binaries - contains the built .exe and .lib files from the projects.

    • Build – contains .exe/.dll files and game assets (.wav, images, models).

    • Intermediate - contains the temporary object files (.obj) from the projects.

    • Source - contains source code and projects.

image
  • The Game project will be moved into the Source folder.

  • In Visual Studio click on the Game project in the Solution Explorer, press Delete to remove the project.

    • Save the project if prompted.
image
image
  • In Windows Explorer, move the Game folder into the Source folder.
image
  • In Visual Studio, right-click the Solution in the Solution Explorer and select Add>Existing Project…
image
  • Find the project file (Game.vcxproj) and click Open.
image
  • The Project will now be included in the Solution.
image

Update the Game Project

The Game project is a project that will contain the code for the game and creates an executable (.exe) that can be run.

  • The Solution will contain default Filters (folders) for the Game project.

  • Remove and Rename the Filters as follows:

    • Remove Resource Files.

    • Remove Header Files.

    • Rename Source Files to “Source”.

image
image
  • Add a Main.cpp to the Source filter.

    • Right click on the Source filter and select Add>New Item…
image
  • Name the file Main.cpp and click Add.
image
  • Typically the source file that contains the main() function is called Main.cpp.

  • The main() function is the entry point for the application, where the program will start.

image
  • Add the following code to display the classic “Hello World!”
1
2
3
4
5
#include <iostream>
int main()
{
  std::cout << "Hello, World!\n";
}
  • Run (F5) the project to ensure it is working
image

Add an Engine Static Library

  • In Visual Studio, right-click the Solution in the Solution Explorer and select Add>New Project…
image
  • Find and select the Windows Desktop Wizard, click Next.
image
  • Set the Project name to “Engine”

  • Click the Location button to select the location for the project.

    • Navigate to the Source folder.
image
image
  • Click Select Folder.
image
  • Click Create.
image
  • Set the Application type to Static Library (.lib) and check the Empty Project
image
  • There will now be an Engine Project and Game Project in the Solution.
image
  • Remove and Rename the Filters as follows:

    • Remove Resource Files.

    • Rename Header Files to “Include”.

    • Rename Source Files to “Source”.

image
  • Add an Engine.cpp to the Source filter in the Engine Project.

    • Right click on the Source filter and select Add>New Item…
image
  • Name the .cpp file “Engine.cpp”
image
  • This will create an Engine.cpp file to the Engine Project.

    • No code will be added to this file, it is needed to build the Solution.
image

Add Reference to Engine

A reference to the Engine library project needs to be add to the Game project. This will allow the Game project to use code generated in the Engine library project.

  • Right-click on the Game References in the Game Project and select Add Reference…
image
  • Select Engine and click OK to add the Engine Project library to the Game Project.
image
image

Create a Git Repository

  • Click Add to Source Control located at the bottom right of the Visual Studio IDE.

  • Select Git.

image
  • Your credentials should be set if you have used Git with Visual Studio before.

  • The Repository name can be left with the default Solution name CSC196 or can be changed.

  • Uncheck the Private repository so it can be accessed, it is important to do this step for grading.

  • Click Create and Push to create the repository and push the current project onto GitHub.

image
  • Navigate to your GitHub repository page to ensure it has been created.

    • It may take a couple of minutes to appear when created.
image

Save changes to GitHub

Changes to the Solution can be committed to GitHub from inside Visual Studio.

  • Save the changes to the project to the remote repository (GitHub).

    • Select the Git Changes tab at the bottom of the Solution Explorer.
image
  • If the Git Changes tab isn’t visible, open it with View>Git Changes (Ctrl+0, Ctrl+G).
image
  • Enter a message (description of what was done) for the commit.

  • Click Commit All.

image
  • Press the Push button to push the changes to the remote repository (GitHub)
image
  • A status message will be displayed
image
This post is licensed under CC BY 4.0 by the author.