You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# C/C++ projects and build systems in Visual Studio
11
10
12
11
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.
13
12
14
13
## C++ compilation
15
14
16
-
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).
15
+
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-link library (`.dll`) or a static library (`.lib`).
17
16
18
17
Basic C++ compilation involves three main steps:
19
18
20
19
- The C++ preprocessor transforms all the #directives and macro definitions in each source file. This creates a *translation unit*.
21
-
- The C++ compiler compiles each translation unit into object files (.obj), applying whatever compiler options have been set.
20
+
- The C++ compiler compiles each translation unit into object files (`.obj`), applying whatever compiler options have been set.
22
21
- The *linker* merges the object files into a single executable, applying the linker options that have been set.
23
22
24
23
## The Microsoft C++ (MSVC) Build Tools
25
24
26
25
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](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022) on the Visual Studio Downloads page.
27
26
28
-
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*:
27
+
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`*:
29
28
30
29
```cmd
31
30
cl /EHsc hello.cpp
32
31
```
33
32
34
-
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](building-on-the-command-line.md).
33
+
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](building-on-the-command-line.md).
35
34
36
35
## Build systems and projects
37
36
38
37
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*.
39
38
40
39
The following list shows various options for Visual Studio Projects - C++:
41
40
42
-
-create a Visual Studio project by using the Visual Studio IDE and configure it by using property pages. Visual Studio projects produce programs that run on Windows. For an overview, see [Compiling and Building](/visualstudio/ide/compiling-and-building-in-visual-studio) in the Visual Studio documentation.
41
+
-Create a Visual Studio project by using the Visual Studio IDE and configure it by using property pages. Visual Studio projects produce programs that run on Windows. For an overview, see [Compiling and Building](/visualstudio/ide/compiling-and-building-in-visual-studio) in the Visual Studio documentation.
43
42
44
-
-open a folder that contains a CMakeLists.txt file. CMake support is integrated into Visual Studio. You can use the IDE to edit, test, and debug without modifying the CMake files in any way. This enables you to work in the same CMake project as others who might be using different editors. CMake is the recommended approach for cross-platform development. For more information, see [CMake projects](cmake-projects-in-visual-studio.md).
43
+
-Open a folder that contains a `CMakeLists.txt` file. CMake support is integrated into Visual Studio. You can use the IDE to edit, test, and debug without modifying the CMake files in any way. This enables you to work in the same CMake project as others who might be using different editors. CMake is the recommended approach for cross-platform development. For more information, see [CMake projects](cmake-projects-in-visual-studio.md).
45
44
46
-
-open a loose folder of source files with no project file. Visual Studio will use heuristics to build the files. This is an easy way to compile and run small console applications. For more information, see [Open Folder projects](open-folder-projects-cpp.md).
45
+
-Open a loose folder of source files with no project file. Visual Studio will use heuristics to build the files. This is an easy way to compile and run small console applications. For more information, see [Open Folder projects](open-folder-projects-cpp.md).
47
46
48
-
-open a folder that contains a makefile, or any other build system configuration file. You can configure Visual Studio to invoke any arbitrary build commands by adding JSON files to the folder. For more information, see [Open Folder projects](open-folder-projects-cpp.md).
47
+
-Open a folder that contains a makefile, or any other build system configuration file. You can configure Visual Studio to invoke any arbitrary build commands by adding JSON files to the folder. For more information, see [Open Folder projects](open-folder-projects-cpp.md).
49
48
50
49
- Open a Windows makefile in Visual Studio. For more information, see [NMAKE Reference](reference/nmake-reference.md).
51
50
52
51
## MSBuild from the command line
53
52
54
-
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](msbuild-visual-cpp.md).
53
+
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](msbuild-visual-cpp.md).
55
54
56
55
## In This Section
57
56
@@ -74,7 +73,7 @@ Discusses how to use the C/C++ compiler and build tools directly from the comman
74
73
How to create, debug, and deploy C/C++ DLLs (shared libraries) in Visual Studio.
75
74
76
75
[Walkthrough: Creating and Using a Static Library](walkthrough-creating-and-using-a-static-library-cpp.md)\
77
-
How to create a **.lib** binary file.
76
+
How to create a `.lib` binary file.
78
77
79
78
[Building C/C++ Isolated Applications and Side-by-side Assemblies](building-c-cpp-isolated-applications-and-side-by-side-assemblies.md)\
80
79
Describes the deployment model for Windows Desktop applications, based on the idea of isolated applications and side-by-side assemblies.
@@ -86,7 +85,7 @@ How to target 64-bit x64 hardware with the MSVC build tools.
86
85
How to use the MSVC Build Tools to target ARM hardware.
87
86
88
87
[Optimizing Your Code](optimizing-your-code.md)\
89
-
How to optimize your code in various ways including program guided optimizations.
88
+
How to optimize your code in various ways including profile-guided optimization (PGO).
90
89
91
90
[Configuring Programs for Windows XP](configuring-programs-for-windows-xp.md)\
92
91
How to target Windows XP with the MSVC build tools.
Copy file name to clipboardExpand all lines: docs/build/reference/zc-conformance.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Here are the **`/Zc`** compiler options:
30
30
|[`/Zc:checkGwOdr[-]`](zc-check-gwodr.md)| Enforce Standard C++ ODR violations under `/Gw`. |
31
31
|[`/Zc:enumTypes[-]`](zc-enumtypes.md)| Enable Standard C++ rules for `enum` type deduction. Off by default. |
32
32
|[`/Zc:externC[-]`](zc-externc.md)| Enforce Standard C++ rules for `extern "C"` functions. Off by default unless **`/permissive-`** is specified. |
33
-
|[`/Zc:externConstexpr[-]`](zc-externconstexpr.md)| Enable external linkage for **`constexpr`** variables. Off by default. |
33
+
|[`/Zc:externConstexpr[-]`](zc-externconstexpr.md)| Enable external linkage for **`constexpr`** variables. Off by default unless **`/permissive-`** is specified. |
34
34
|[`/Zc:forScope[-]`](zc-forscope-force-conformance-in-for-loop-scope.md)| Enforce Standard C++ **`for`** scoping rules. On by default. |
35
35
|[`/Zc:gotoScope[-]`](zc-gotoscope.md)| Enforce Standard C++ **`goto`** rules around local variable initialization. Off by default unless **`/permissive-`** is specified. |
36
36
|[`/Zc:hiddenFriend[-]`](zc-hiddenfriend.md)| Enforce Standard C++ hidden friend rules. Off by default unless **`/permissive-`** is specified. |
You can either allocate these storage buffers manually or have the framework do the allocation. To allocate the buffers yourself, you must specify the `CRecordset::userAllocMultiRowBuffers` option of the *dwOptions* parameter in the `Open` member function. Be sure to set the sizes of the arrays at least equal to the rowset size. If you want to have the framework do the allocation, you should initialize your pointers to NULL. This is typically done in the recordset object's constructor:
description: "Learn more about: Compiler Error C2135"
4
-
ms.date: 11/04/2016
4
+
ms.date: 08/13/2025
5
5
f1_keywords: ["C2135"]
6
6
helpviewer_keywords: ["C2135"]
7
7
---
8
8
# Compiler Error C2135
9
9
10
-
> 'bit operator' : illegal bitfield operation
10
+
> '*identifier*': you cannot apply '*operator*' to a bit-field
11
11
12
12
## Remarks
13
13
14
-
The address-of operator (`&`)cannot be applied to a bitfield.
14
+
The [address-of operator (`&`)](../../cpp/address-of-operator-amp.md), [unary plus operator (`+`)](../../cpp/unary-plus-and-negation-operators-plus-and.md), [unary negation operator (`-`)](../../cpp/unary-plus-and-negation-operators-plus-and.md), [logical negation operator (`!`)](../../cpp/logical-negation-operator-exclpt.md), [one's complement operator (`~`)](../../cpp/one-s-complement-operator-tilde.md), and [indirection operator (`*`)](../../cpp/indirection-operator-star.md)cannot be applied to a bit-field in this context.
A **`mutable`** specifier was used in a declaration, but the specifier is not allowed in this context.
14
+
A **`mutable`** specifier was used in a declaration, but the specifier is not allowed in this context. It can only be applied to non-static, non-const, and non-reference data members. For more information, see [Mutable Data Members](../../cpp/mutable-data-members-cpp.md).
15
15
16
-
The**`mutable`** specifier can be applied only to names of class data members, and cannot be applied to names declared **`const`**or **`static`**, and cannot be applied to reference members.
16
+
A**`consteval`** specifier was used on a [destructor](../../cpp/destructors-cpp.md), allocation function, or deallocation function.
17
17
18
-
## Example
18
+
## Example: `mutable`
19
19
20
-
The following example shows how C2178 may occur, and how to fix it.
20
+
The following example shows how C2178 may occur with the **`mutable`** specifier, and how to resolve it:
21
21
22
22
```cpp
23
-
//C2178.cpp
24
-
// compile with: cl /c /W4 C2178.cpp
23
+
//C2178_mutable.cpp
24
+
// compile with: /c
25
25
26
-
classS {
27
-
mutable const int i; // C2178
28
-
// To fix, declare either const or mutable, not both.
26
+
structS
27
+
{
28
+
mutable const int i; // C2178, remove mutable or const to resolve
29
29
};
30
30
31
-
mutable int x = 4; // C2178
32
-
// To fix, remove mutable keyword
31
+
mutableint x = 4; // C2178, remove mutable to resolve
32
+
```
33
+
34
+
## Example: `consteval`
35
+
36
+
The following example shows how C2178 may occur with the **`consteval`** specifier. To resolve this error, remove all **`consteval`** specifiers:
description: "Learn more about: Compiler Error C2190"
4
-
ms.date: 11/04/2016
4
+
ms.date: 08/22/2025
5
5
f1_keywords: ["C2190"]
6
6
helpviewer_keywords: ["C2190"]
7
7
---
@@ -11,7 +11,7 @@ helpviewer_keywords: ["C2190"]
11
11
12
12
## Remarks
13
13
14
-
A C function was declared a second time with a shorter parameter list. C does not support overloaded functions.
14
+
A C function was declared a second time with a shorter parameter list. C does not support overloaded functions. Without [`/Za`](../../build/reference/za-ze-disable-language-extensions.md), the compiler emits [Compiler Warning (level 1) C4030](../compiler-warnings/compiler-warning-level-1-c4030.md) instead.
15
15
16
16
## Example
17
17
@@ -20,7 +20,13 @@ The following example generates C2190:
20
20
```c
21
21
// C2190.c
22
22
// compile with: /Za /c
23
-
voidfunc( int, float );
24
-
void func( int ); // C2190, different parameter list
description: "Learn more about: Compiler Error C2191"
4
-
ms.date: 11/04/2016
4
+
ms.date: 08/22/2025
5
5
f1_keywords: ["C2191"]
6
6
helpviewer_keywords: ["C2191"]
7
7
---
@@ -11,7 +11,7 @@ helpviewer_keywords: ["C2191"]
11
11
12
12
## Remarks
13
13
14
-
A C function was declared a second time with a longer parameter list. C does not support overloaded functions.
14
+
A C function was declared a second time with a longer parameter list. C does not support overloaded functions. Without [`/Za`](../../build/reference/za-ze-disable-language-extensions.md), the compiler emits [Compiler Warning (level 1) C4031](../compiler-warnings/compiler-warning-level-1-c4031.md) instead.
15
15
16
16
## Example
17
17
@@ -20,7 +20,13 @@ The following example generates C2191:
20
20
```c
21
21
// C2191.c
22
22
// compile with: /Za /c
23
-
voidfunc( int );
24
-
void func( int, float ); // C2191 different parameter list
25
-
void func2( int, float ); // OK
23
+
24
+
voidfunc1(int);
25
+
void func1(int, float); // C2191, longer parameter list
description: "Learn more about: Compiler Error C2277"
4
-
ms.date: 11/04/2016
4
+
ms.date: 08/27/2025
5
5
f1_keywords: ["C2277"]
6
6
helpviewer_keywords: ["C2277"]
7
7
---
8
8
# Compiler Error C2277
9
9
10
-
> 'identifier' : cannot take address of this member function
10
+
> '*function*': cannot take address of this member function
11
11
12
12
## Remarks
13
13
14
-
You cannot take the address of a member function.
14
+
You cannot take the address of a [constructor](../../cpp/constructors-cpp.md) or [destructor](../../cpp/destructors-cpp.md). For more information, see [Address-of operator: `&`](../../cpp/address-of-operator-amp.md) and [Pointers to Members](../../cpp/pointers-to-members.md).
0 commit comments