Skip to content

Commit 24a273d

Browse files
authored
Merge pull request #4533 from corob-msft/docs/corob/vcsig-scandependencies-fix
Update /scanDependencies to add /std requirement for modules
2 parents 0fb4e8b + 23fb024 commit 24a273d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

docs/build/reference/scandependencies.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "/scanDependencies (List module and header unit dependencies per Standard)"
33
description: "Reference guide to the /scanDependencies compiler option in Microsoft C++."
4-
ms.date: 05/19/2022
4+
ms.date: 09/21/2022
55
author: "corob-msft"
66
ms.author: "corob"
77
f1_keywords: ["/scanDependencies"]
@@ -11,17 +11,6 @@ helpviewer_keywords: ["/scanDependencies compiler option", "/scanDependencies"]
1111

1212
This compiler option generates a JSON file that lists module and header-unit dependencies according to C++ Standard proposal [`P1689R4 Format for describing dependencies of source files`](https://wg21.link/P1689r4).
1313

14-
The **`/scanDependencies`** compiler option identifies which modules and header units need to be compiled before you can compile the project that uses them. For instance, it lists `import <library>;` or `import "library";` as a header unit dependency, and `import name;` as a module dependency. The intent is to provide this information in a common format consumable by build tools such as CMake.
15-
16-
This command-line option is similar to [`/sourceDependencies:directives`](sourcedependencies-directives.md) and [`/sourceDependencies`](sourcedependencies.md), but differs in the following ways:
17-
18-
- The output uses the [`P1689R4`](https://wg21.link/P1689r4) schema, instead of the Microsoft-specific schema generated by **`/sourceDependencies:directives`**.
19-
- Unlike **`/sourceDependencies`**, the compiler doesn't produce compiled output. Instead, the files are scanned for module directives. No compiled code, modules, or header units are produced.
20-
- The output JSON file doesn't list imported modules and imported header units (*`.ifc`* files) because this option only scans the project files. There are no built modules or header units to list.
21-
- Only directly imported modules or header units are listed. It doesn't list the dependencies of the imported modules or header units themselves.
22-
- Textually included header files such as `#include <file>` or `#include "file"` aren't listed as dependencies unless translated to a header unit by using the [`/translateInclude`](translateinclude.md) option.
23-
- **`/scanDependencies`** is meant to be used before *`.ifc`* files are built.
24-
2514
## Syntax
2615

2716
> **`/scanDependencies-`**\
@@ -41,9 +30,20 @@ If the argument is a directory, the compiler generates source dependency files i
4130

4231
## Remarks
4332

44-
**`/scanDependencies`** is available starting in Visual Studio 2022 version 17.2 preview 1. It's not enabled by default.
33+
The **`/scanDependencies`** compiler option identifies which dependencies, modules, and header units must be compiled before you can compile the project that uses them. For instance, it lists `import <library>;` or `import "library";` as a header unit dependency, and `import name;` as a module dependency. The intent is to provide this information in a common format consumable by build tools such as CMake. To report module and header unit dependencies, you must also compile by using [`/std:c++20`](std-specify-language-standard-version.md) or later.
34+
35+
This command-line option is similar to [`/sourceDependencies:directives`](sourcedependencies-directives.md) and [`/sourceDependencies`](sourcedependencies.md), but differs in the following ways:
4536

46-
When you specify the [`/MP` (Build with multiple processes)](mp-build-with-multiple-processes.md) compiler option, we recommend you use **`/scanDependencies`** with a directory argument. If you provide a single filename argument, two instances of the compiler may attempt to open the output file simultaneously and cause an error. Use of **`/MP`** with **`/scanDependencies-`** to send output to `stdout` could cause interleaved results.
37+
- The output uses the [`P1689R4`](https://wg21.link/P1689r4) schema, instead of the Microsoft-specific schema generated by **`/sourceDependencies:directives`**.
38+
- Unlike **`/sourceDependencies`**, the compiler doesn't produce compiled output. Instead, the files are scanned for module directives. No compiled code, modules, or header units are produced.
39+
- The output JSON file doesn't list imported modules and imported header units (*`.ifc`* files) because this option only scans the project files. There are no built modules or header units to list.
40+
- Only directly imported modules or header units are listed. It doesn't list the dependencies of the imported modules or header units themselves.
41+
- Textually included header files such as `#include <file>` or `#include "file"` aren't listed as dependencies unless translated to a header unit by using the [`/translateInclude`](translateinclude.md) option.
42+
- **`/scanDependencies`** is meant to be used before *`.ifc`* files are built.
43+
44+
**`/scanDependencies`** is available starting in Visual Studio 2022 version 17.2. It's not enabled by default.
45+
46+
When you specify the [`/MP` (Build with multiple processes)](mp-build-with-multiple-processes.md) compiler option, we recommend that you use **`/scanDependencies`** with a directory argument. If you provide a single filename argument, two instances of the compiler may attempt to open the output file simultaneously and cause an error. Use of **`/MP`** with **`/scanDependencies-`** to send output to `stdout` could cause interleaved results.
4747

4848
When a non-fatal compiler error occurs, the dependency information still gets written to the output file.
4949

@@ -53,7 +53,7 @@ For details on the format and schema used in the output JSON file, see [`P1689R4
5353

5454
### Examples
5555

56-
Given the following sample code:
56+
Consider the following sample code:
5757

5858
```cpp
5959
//app.cpp:
@@ -69,9 +69,11 @@ import <iostream>;
6969
int main() {}
7070
```
7171

72+
You can use this command line to report dependencies in *`app.cpp`*:
73+
7274
> `cl /std:c++latest /scanDependencies output.json app.cpp`
7375
74-
This command line produces a JSON file *`output.json`* with content similar to:
76+
The compiler produces a JSON file, *`output.json`*, with content similar to:
7577

7678
```JSON
7779
{
@@ -114,16 +116,18 @@ No *`.ifc`* files are listed in the output because they weren't built. Unlike **
114116

115117
## To set this compiler option in Visual Studio
116118

117-
You normally shouldn't set this option yourself in the Visual Studio development environment. The compiler doesn't generate object files when you set this option, which makes the link step fail and report an error.
119+
You normally shouldn't set the **`/scanDependencies`** option in the Visual Studio development environment. The compiler doesn't generate object files when you set this option, which makes the link step fail and report an error.
118120

119-
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
121+
1. Open the project's **Property Pages** dialog box. For more information, see [Set compiler and build properties](../working-with-project-properties.md).
120122

121123
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
122124

123-
1. Modify the **Additional Options** property to add **`/scanDependencies -`** or **`/scanDependencies "pathname"`**, where `pathname` refers to a directory for output.
125+
1. Modify the **Additional Options** property to add *`/scanDependencies-`* or *`/scanDependencies "pathname"`*, where *`"pathname"`* refers to a directory for output.
124126

125127
1. Choose **OK** to save your changes.
126128

129+
To report module and header unit dependencies, you must also set the **Configuration Properties** > **General** > **C++ Language Standard** property to **ISO C++20 Standard** or later.
130+
127131
### To set this compiler option programmatically
128132

129133
- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions%2A>.
@@ -134,4 +138,5 @@ You normally shouldn't set this option yourself in the Visual Studio development
134138
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\
135139
[`/sourceDependencies:directives`](sourcedependencies-directives.md)\
136140
[`/sourceDependencies`](sourcedependencies.md)\
141+
[`/std` (Specify language standard version)](std-specify-language-standard-version.md)\
137142
[`/translateInclude`](translateinclude.md)

0 commit comments

Comments
 (0)