Skip to content

Commit ab6741b

Browse files
TylerMSFTTylerMSFT
authored andcommitted
break compile/link into 2 steps
1 parent 7b93491 commit ab6741b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ The statement `import std;` or `import std.compat;` imports the standard library
109109
1. Compile the example by using the following command in the same directory as the previous step:
110110
111111
```cmd
112-
cl /std:c++latest /EHsc /nologo /W4 /reference "std=std.ifc" importExample.cpp std.obj
112+
cl /c /std:c++latest /EHsc /nologo /W4 /reference "std=std.ifc" importExample.cpp
113+
link importExample.obj std.obj
113114
```
114115
115116
It isn't necessary to specify `/reference "std=std.ifc"` on the command line in this example because the compiler automatically looks for the `.ifc` file matching the module name specified by the `import` statement. When the compiler encounters `import std;`, it can find `std.ifc` if it is located in the same directory as the source code. If the `.ifc` file is in a different directory than the source code, use the [`/reference`](../build/reference/module-reference.md) compiler switch to refer to it.
116117
118+
In this example, compiling your source code and linking the module's implementation into your application are separate steps. They don't have to be. You could have used `cl /std:c++latest /EHsc /nologo /W4 /reference "std=std.ifc" importExample.cpp std.obj` to compile and link in one step. But it may be convenient to build and link separately. For example, you only need to build the standard library named module once, and then you can refer to it from your project, or from multiple projects.
119+
117120
If you're building a single project, you can combine the steps of building the `std` standard library named module and the step of building your application by adding `"%VCToolsInstallDir%\modules\std.ixx"` to the command line. Make sure to put it before any `.cpp` files that consume it. By default, the output executable's name is taken from the first input file. Use the `/Fe` compiler option to specify the output file name you want. This tutorial shows compiling the `std` named module as a separate step because you only need to build the standard library named module once, and then you can refer to it from your project, or from multiple projects. But it may be convenient to build everything together, as shown by this command line:
118121
119122
```cmd

0 commit comments

Comments
 (0)