In order to compile and run code from Visual Studio, it must be done from within a project.
In this recipe, we will identify how to create an actual executable running program from Visual Studio. We will do so by creating a project in Visual Studio to host, organize, and compile the code.
In Visual Studio, each group of code is contained within something called a
Project. A Project is a buildable conglomerate of code and assets that produce either an executable (.exe
runnable) or a library (.lib
, or .dll
). A group of Projects can be collected together into something called a
Solution. Let's start by constructing a Visual Studio Solution and Project for a console application, followed by constructing a UE4 sample Project and Solution.
Select Win32 in the pane on the left-hand side. In the right-hand pane, hit Win32 Console Application. Name your project in the lower box, then hit OK.
Solution Explorer also displays all the files that are part of the project. Using Solution Explorer, we will also add a code file into the editor. Right click on your Project FirstProject
, and select Add | New Item…
Main.cpp
.FirstProject
's source file filter. As your Project grows, more and more files are going to be added to your project. You can compile and run your first C++ program using the following text:#include<stdio.h> int main() { puts("Welcome to Visual Studio 2015 Community Edition!"); }
Building an executable involves translating your C++ code from text language to a binary file. Running the file runs your game program, which is just the code text that occurs in the main()
function between {
and }
.
Build configurations are styles of build that we should discuss them here. There are at least two important build configurations you should know about: Debug and Release. The Build configuration selected is at the top of the editor, just below the toolbar in the default position.
Depending on which configuration you select, different compiler options are used. A Debug configuration typically includes extensive debug information in the build as well as turning off optimizations to speed up compilation. Release builds are often optimized (either for size or for speed), take a bit longer to build, and result in smaller or faster executables. Behavior stepping through with the debugger is often better in the Debug mode than the Release mode.
18.222.108.18