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
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).
13
13
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
-
25
14
## Syntax
26
15
27
16
> **`/scanDependencies-`**\
@@ -41,9 +30,20 @@ If the argument is a directory, the compiler generates source dependency files i
41
30
42
31
## Remarks
43
32
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:
45
36
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.
47
47
48
48
When a non-fatal compiler error occurs, the dependency information still gets written to the output file.
49
49
@@ -53,7 +53,7 @@ For details on the format and schema used in the output JSON file, see [`P1689R4
53
53
54
54
### Examples
55
55
56
-
Given the following sample code:
56
+
Consider the following sample code:
57
57
58
58
```cpp
59
59
//app.cpp:
@@ -69,9 +69,11 @@ import <iostream>;
69
69
intmain() {}
70
70
```
71
71
72
+
You can use this command line to report dependencies in *`app.cpp`*:
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:
75
77
76
78
```JSON
77
79
{
@@ -114,16 +116,18 @@ No *`.ifc`* files are listed in the output because they weren't built. Unlike **
114
116
115
117
## To set this compiler option in Visual Studio
116
118
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.
118
120
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).
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.
124
126
125
127
1. Choose **OK** to save your changes.
126
128
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
+
127
131
### To set this compiler option programmatically
128
132
129
133
- 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
0 commit comments