Skip to content

Commit 46171dd

Browse files
Merge pull request #6125 from MicrosoftDocs/main
Auto Publish – main to live - 2025-10-22 17:30 UTC
2 parents 30c2b48 + c4739f2 commit 46171dd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/cpp/tutorial-import-stl-named-module.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: "Tutorial: Import the standard library (STL) using modules from the command line (C++)"
3+
description: "Learn how to import the C++ standard library (STL) using modules from the command line."
34
ms.date: 01/29/2024
45
ms.topic: "tutorial"
56
author: "tylermsft"
67
ms.author: "twhitney"
7-
helpviewer_keywords: ["modules [C++]", "modules [C++]", "named modules [C++], import standard library (STL) using named modules"]
8-
description: Learn how to import the C++ standard library (STL) using modules from the command line
8+
helpviewer_keywords: ["modules [C++]", "named modules [C++], import standard library (STL) using named modules"]
99
---
1010

1111
# Tutorial: Import the C++ standard library using modules from the command line
@@ -26,7 +26,7 @@ This tutorial requires Visual Studio 2022 17.5 or later.
2626

2727
Header file semantics can change depending on macro definitions, the order in which you include them, and they slow compilation. Modules solve these problems.
2828

29-
It's now possible to import the standard library as a module instead of as a tangle of header files. This is much faster and more robust than including header files or header units or precompiled headers (PCH).
29+
It's now possible to import the standard library as a module instead of as a tangle of header files. This is much faster and more robust than including header files, header units, or precompiled headers (PCH).
3030

3131
The C++23 standard library introduces two named modules: `std` and `std.compat`:
3232

@@ -49,7 +49,7 @@ This article demonstrates the new and best way to consume the standard library.
4949

5050
## Import the standard library with `std`
5151

52-
The following examples demonstrate how to consume the standard library as a module using the command line compiler. For information about how to do this in the Visual Studio IDE, see [Build ISO C++23 Standard Library Modules](..\build\reference\c-cpp-prop-page.md#build-iso-c23-standard-library-modules).
52+
The following examples demonstrate how to consume the standard library as a module using the command line compiler. For information about how to do this in the Visual Studio IDE, see [Build ISO C++23 Standard Library Modules](../build/reference/c-cpp-prop-page.md#build-iso-c23-standard-library-modules).
5353

5454
The statement `import std;` or `import std.compat;` imports the standard library into your application. But first, you must compile the standard library named modules into binary form. The following steps demonstrate how.
5555

@@ -75,9 +75,9 @@ The statement `import std;` or `import std.compat;` imports the standard library
7575
7676
| Switch | Meaning |
7777
|---|---|
78-
| [`/std:c++:latest`](../build/reference/std-specify-language-standard-version.md) | Use the latest version of the C++ language standard and library. Although module support is available under `/std:c++20`, you need the latest standard library to get support for standard library named modules. |
78+
| [`/std:c++latest`](../build/reference/std-specify-language-standard-version.md) | Use the latest version of the C++ language standard and library. Although module support is available under `/std:c++20`, you need the latest standard library to get support for standard library named modules. |
7979
| [`/EHsc`](../build/reference/eh-exception-handling-model.md) | Use C++ exception handling, except for functions marked `extern "C"`. |
80-
| [`/W4`](../build/reference//compiler-option-warning-level.md) | Using /W4 is generally recommended, especially for new projects because it enables all level 1, level 2, level 3, and most level 4 (informational) warnings, which can help you catch potential issues early. It essentially provides lint-like warnings that can help ensure the fewest possible hard-to-find code defects. |
80+
| [`/W4`](../build/reference/compiler-option-warning-level.md) | Using `/W4` is generally recommended, especially for new projects because it enables all level 1, level 2, level 3, and most level 4 (informational) warnings, which can help you catch potential issues early. It essentially provides lint-like warnings that can help ensure the fewest possible hard-to-find code defects. |
8181
| [`/c`](../build/reference/c-compile-without-linking.md) | Compile without linking, because we're just building the binary named module interface at this point. |
8282
8383
You can control the object file name and the named module interface file name with the following switches:
@@ -159,7 +159,7 @@ Before you can use `import std.compat;` you must compile the module interface fi
159159
- `std.compat.obj` contains implementation. However, most of the implementation is provided by `std.obj`. Add `std.obj` to the command line when you compile the sample app to statically link the functionality that you use from the standard library into your application.
160160
161161
You can control the object file name and the named module interface file name with the following switches:
162-
- [`/Fo`](../build/reference/fo-object-file-name.md) sets the name of the object file. For example, `/Fo:"somethingelse"`. By default, the compiler uses the same name for the object file as the module source file (`.ixx`) you're compiling. In the example, the object file names are `std.obj` and `std.compat.obj` by default because we're compiling the module files `std.ixx` and `std.compat.obj`.
162+
- [`/Fo`](../build/reference/fo-object-file-name.md) sets the name of the object file. For example, `/Fo:"somethingelse"`. By default, the compiler uses the same name for the object file as the module source file (`.ixx`) you're compiling. In the example, the object file names are `std.obj` and `std.compat.obj` by default because we're compiling the module files `std.ixx` and `std.compat.ixx`.
163163
- [`/ifcOutput`](../build/reference/ifc-output.md) sets the name of the named module interface file (`.ifc`). For example, `/ifcOutput "somethingelse.ifc"`. By default, the compiler uses the same name for the module interface file (`.ifc`) as the module source file (`.ixx`) you're compiling. In the example, the generated `ifc` files are `std.ifc` and `std.compat.ifc` by default because we're compiling the module files `std.ixx` and `std.compat.ixx`.
164164
165165
1. Import the `std.compat` library by first creating a file named `stdCompatExample.cpp` with the following content:
@@ -210,7 +210,7 @@ Before you can use `import std.compat;` you must compile the module interface fi
210210
211211
## Standard library named module considerations
212212
213-
Versioning for named modules is the same as for headers. The `.ixx` named module files are installed alongside the headers, for example: `"%VCToolsInstallDir%\modules\std.ixx`, which resolves to `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\modules\std.ixx` in the version of the tools used at the time of this writing. Select the version of the named module the same way you choose the version of the header file to use--by the directory you refer to them from.
213+
Versioning for named modules is the same as for headers. The `.ixx` named module files are installed alongside the headers, for example: `"%VCToolsInstallDir%\modules\std.ixx"`, which resolves to `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\modules\std.ixx` in the version of the tools used at the time of this writing. Select the version of the named module the same way you choose the version of the header file to use--by the directory you refer to them from.
214214
215215
Don't mix and match importing header units and named modules. For example, don't `import <vector>;` and `import std;` in the same file.
216216
@@ -222,7 +222,7 @@ If you need to use the `assert()` macro, then `#include <assert.h>`.
222222
223223
If you need to use the `errno` macro, `#include <errno.h>`. Because named modules don't expose macros, this is the workaround if you need to check for errors from `<math.h>`, for example.
224224
225-
Macros such as `NAN`, `INFINITY`, and `INT_MIN` are defined by `<limits.h>`, which you can include. However, if you `import std;` you can use `numeric_limits<double>::quiet_NaN()` and `numeric_limits<double>::infinity()` instead of `NAN` and `INFINITY`, and `std::numeric_limits<int>::min()` instead of `INT_MIN`.
225+
Macros such as `NAN`, `INFINITY`, and `INT_MIN` are defined by `<limits.h>`, which you can include. However, if you `import std;` you can use `std::numeric_limits<double>::quiet_NaN()` and `std::numeric_limits<double>::infinity()` instead of `NAN` and `INFINITY`, and `std::numeric_limits<int>::min()` instead of `INT_MIN`.
226226
227227
## Summary
228228

0 commit comments

Comments
 (0)