C/C++ projects and build systems in Visual Studio (original) (raw)

You can use Visual Studio to edit, compile, and build any C++ code base with full IntelliSense support without having to convert that code into a Visual Studio project or compile with the Microsoft C++ (MSVC) Build Tools. For example, you can edit a cross-platform CMake project in Visual Studio on a Windows machine, then compile it for Linux using g++ on a remote Linux machine.

C++ compilation

To build a C++ program means to compile source code from one or more files and then link those files into an executable file (.exe), a dynamic-load library (.dll) or a static library (.lib).

Basic C++ compilation involves three main steps:

The Microsoft C++ compiler, linker, standard libraries, and related utilities make up the Microsoft C++ (MSVC) Build Tools (also called a toolchain or toolset). These are included in Visual Studio. You can also download and use the command-line toolset as a free standalone package. For more information, see Build Tools for Visual Studio on the Visual Studio Downloads page.

You can build simple programs by invoking the MSVC compiler (cl.exe) directly from the command line. The following command accepts a single source code file, and invokes cl.exe to build an executable called hello.exe:

cl /EHsc hello.cpp

Here the compiler (cl.exe) automatically invokes the C++ preprocessor and the linker to produce the final output file. For more information, see Building on the command line.

Build systems and projects

Most real-world programs use some kind of build system to manage complexities of compiling multiple source files for multiple configurations (debug vs. release), multiple platforms (x86, x64, ARM, and so on), custom build steps, and even multiple executables that must be compiled in a certain order. You make settings in a build configuration file(s), and the build system accepts that file as input before it invokes the compiler. The set of source code files and build configuration files needed to build an executable file is called a project.

The following list shows various options for Visual Studio Projects - C++:

MSBuild from the command line

You can invoke MSBuild from the command line by passing it a .vcxproj file along with command-line options. This approach requires a good understanding of MSBuild, and is recommended only when necessary. For more information, see MSBuild.

In This Section

Visual Studio projects
How to create, configure, and build C++ projects in Visual Studio using its native build system (MSBuild).

CMake projects
How to code, build, and deploy CMake projects in Visual Studio.

Open Folder projects
How to use Visual Studio to code, build, and deploy C++ projects based on any arbitrary build system, or no build system at all.

Release builds
How to create and troubleshoot optimized release builds for deployment to end users.

Use the MSVC toolset from the command line
Discusses how to use the C/C++ compiler and build tools directly from the command line rather than using the Visual Studio IDE.

Building DLLs in Visual Studio
How to create, debug, and deploy C/C++ DLLs (shared libraries) in Visual Studio.

Walkthrough: Creating and Using a Static Library
How to create a .lib binary file.

Building C/C++ Isolated Applications and Side-by-side Assemblies
Describes the deployment model for Windows Desktop applications, based on the idea of isolated applications and side-by-side assemblies.

Configure C++ projects for 64-bit, x64 targets
How to target 64-bit x64 hardware with the MSVC build tools.

Configure C++ projects for ARM processors
How to use the MSVC Build Tools to target ARM hardware.

Optimizing Your Code
How to optimize your code in various ways including program guided optimizations.

Configuring Programs for Windows XP
How to target Windows XP with the MSVC build tools.

C/C++ Building Reference
Provides links to reference articles about program building in C++, compiler and linker options, and various build tools.