There are a lot of things going on so let’s narrow the scope of noise to just the command line options required to compile main.cpp and not link it. $ cl /std:c++latest /reference MyModule=bin\MyModule.ifc src\main.cpp /Fobin\m.obj /Febin\main.exe bin\m.obj Here’s what the fully explicit command lines look like: $ cl /c /std:c++latest src\m.ixx /Fobin\m.obj /ifcOutput bin\MyModule.ifc and that we want all output to go into the bin\ folder. Īnd let’s assume that our compiler command prompt is rooted at. Consider the following directory structure. Let’s consider a scenario where the destination for the resulting IFC is not in the immediate directory. In the scenario above we are trying to import a module interface named MyModule so there might be a MyModule.ifc on disk, and indeed there is! It is worth pointing out that this implicit lookup behavior will search the current directory along with any directory added using /ifcSearchDir. Because the compiler generates a module interface IFC based on the module name it can safely be assumed that if there is no direct /reference option on the command line then there could be an IFC somewhere on disk which is named after the module interface name. Whoa! Hold on there! What happened? Well, in MSVC the compiler implements a well-coordinated lookup to find the module interface implicitly. On the import side we could take advantage of the compiler’s implicit lookup behavior to find the module interface: $ cl /std:c++latest main.cpp m.obj If we take away the two implicit points above, we will end up with a command line which looks like this: $ cl /c /std:c++latest m.ixx /ifcOutput MyModule.ifc /Fom.obj Note that the name of the input file has no bearing on the exported module interface name, they are completely orthogonal to each other so if this file were named foobar.ixx the generated IFC name would still be MyModule.ifc. The resulting IFC in this case is derived from the module name MyModule transformed into MyModule.ifc. The compiler will derive a name for the resulting IFC file based on the module interface name.The resulting object file in this case is derived from m.ixx transformed into m.obj. The compiler will derive a name for the resulting object file based on the base name of the input file.In the first line we compile the module interface, and two things happen implicitly: Here’s a quick example of compiling the module interface if the name were my-module.cppm: $ cl /c /std:c++latest /interface /TP my-module.cppm If you wish to use a different extension then you must use /interface along with /TP in order to compile the input as both C++ and as a module interface. ixx extension is the default module interface extension for MSVC. One quick note about the name of file m.ixx above, the. $ cl /std:c++latest /reference MyModule=MyModule.ifc main.cpp m.obj The simplest way to build this sample is the following: $ cl /c /std:c++latest m.ixx Let’s look at the most basic scenario we can for starters: Specifying this switch will enforce an extra security check using the stored content hash in the IFC.įor the content in this section, we will assume that you have an appropriate compiler environment command prompt set up and that you have navigated to the directory with your test files. When building a header unit, show the fully resolved path to that header unit after compilation. Instructs the compiler to perform #include -> import translation if the header-name nominates an importable header. Tells the compiler that the input designates the name of a header.
Instructs the compiler to create a header unit from the input. No other outputs will be produced as the result of compilation even if other options are specified. Instructs the compiler to only produce an IFC as the result of compilation. If that destination is a directory the compiler will generate a name based on the interface name or the header unit name. Tells the compiler where the IFC resulting from compilation should go.
When the compiler falls back to implicit module interface search, directories specified by this option will be used.
Provides the compiler with an IFC file to reference for the nominated module interface name. Tells the compiler that the input file is an internal partition unit. Tells the compiler that the input file is a module interface unit. Other types of compiler output such as PDB info are not mentioned. Note: This tutorial will focus primarily on dealing with IFC and object file output. The goal of this post is to serve as a brief tour of compiling and using primary module interfaces from the command line and the options we use.
#Cl studio design how to
In this three-part series we will explore how to build modules and header units from the command line as well as how to use/reference them.