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
Copy file name to clipboardExpand all lines: docs/build/walkthrough-header-units.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -40,15 +40,15 @@ You can define additional macros when you build the program that imports the hea
40
40
41
41
There are several ways to compile a file into a header unit:
42
42
43
-
-**Automatically scan for header units**. This approach is best suited to smaller projects that include many different header files. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach1) for a demonstration of this approach. This approach is better suited to smaller projects. That's because it can't guarantee optimal build throughput since it scans all the files to find what should be built into header units.
43
+
-**Automatically scan for header units**. This approach is best suited to smaller projects that include many different header files. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach1) for a demonstration of this approach. This approach is better suited to smaller projectsbecause it can't guarantee optimal build throughput. That's because it scans all the files to find what should be built into header units.
44
44
45
45
-**Build a shared header unit project**. This approach is best suited for larger projects and for when you want more control over the organization of the imported header units. You create a static library project (or projects) that contain the header units that you want. Then reference the library project (or projects) from the project that then imports the header units it needs. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach2) for a demonstration of this approach.
46
46
47
47
-**Choose individual header units to build**. This approach gives you file-by-file control over which header files are treated as header units. It's also a good way to quickly and selectively try out header units in your project. This approach is demonstrated in this walkthrough.
48
48
49
49
## Convert a project to use header units
50
50
51
-
In this example, you'll compile a header file as a header unit. Begin by creating the following project in Visual Studio:
51
+
In this example, you'll compile a header file as a header unit. Start by creating the following project in Visual Studio:
52
52
53
53
1. Create a new C++ console app project.
54
54
1. Replace the source file content as follows:
@@ -72,9 +72,9 @@ In this example, you'll compile a header file as a header unit. Begin by creatin
72
72
}
73
73
```
74
74
75
-
To enable header units, first set the **C++ Language Standard** to [**/std:c++latest**](./reference/std-specify-language-standard-version.md):
75
+
To enable header units, first set the **C++ Language Standard** to [**/std:c++latest**](./reference/std-specify-language-standard-version.md).
76
76
77
-
1.In the Visual Studio main menu, select **Project** > **Properties**.
77
+
1.On the Visual Studio main menu, select **Project** > **Properties**.
78
78
1. In the left pane of the project property pages window, select **Configuration Properties** > **General**.
79
79
1. In the **C++ Language Standard** list, select **Preview - Features from the Latest C++ Working Draft (/std:c++latest)**:
80
80
:::image type="content" source="media/set-cpp-language-latest.png" alt-text="Screenshot that shows setting the language standard to the preview version.":::
@@ -95,7 +95,7 @@ Set the **Compile As** property to **Compile as C++ Header Unit (/exportHeader)*
95
95
96
96
### Change your code to import a header unit
97
97
98
-
In the source file for the example project, that is, the file that contains `main()`, change `#include "Pythagorean.h"` to `import "Pythagorean.h"`. (Don't forget the trailing semicolon that is required for `import` statements.) When you're compiling a header unit from a system header, use angle brackets (`import <file>;`). If it's a project header, use `import "file";`.
98
+
In the source file for the example project, that is, the file that contains `main()`, change `#include "Pythagorean.h"` to `import "Pythagorean.h"`. (Don't forget the trailing semicolon that's required for `import` statements.) When you're compiling a header unit from a system header, use angle brackets (`import <file>;`). If it's a project header, use `import "file";`.
99
99
100
100
Build the solution. (**Build** > **Build Solution** on the main menu.) Run it to see that it produces the expected output: `Pythagorean triple a:2 b:3 c:13`
This walkthrough shows two ways to import C++ Standard Template Library (STL) libraries as header units in Visual Studio.
13
13
14
-
The [first way](#approach1)has the build system automatically scan for and build header units based on the STL headers you import in your project.
14
+
The [first way](#approach1)is to have the build system automatically scan for and build header units based on the STL headers you import in your project.
15
15
16
-
The [second way](#approach2)demonstrates how to build a static library project that contains header units for the STL headers you want to use and then reference that project to import the header units.
16
+
The [second way](#approach2)is to build a static library project that contains header units for the STL headers you want to use and then reference that project to import the header units.
17
17
18
18
Importing an STL header as a header unit is a simpler alternative to [precompiled header files](creating-precompiled-header-files.md). Header units are easier to set up and use than a shared precompiled header file (PCH) but still provide similar performance benefits. Unlike a PCH, when a header unit changes, only it and its dependencies are rebuilt.
19
19
20
-
Before you can import an STL header, it must be compiled into a header unit. A header unit is a binary representation of a header file. A header unit ends with an `.ifc` extension.
20
+
Before you can import an STL header, it must be compiled into a header unit. A header unit is a binary representation of a header file. A header unit ends with an .ifc extension.
21
21
22
22
An important difference between a header unit and a header file is that header units aren't affected by macro definitions. You can't `#define` a symbol that causes the header unit to behave differently when you import it. You can do that with a header file.
0 commit comments