C++ Logo


Advanced search

Re: [isocpp-ext] Can we expect that all C++ source files can have the same suffix?

From: Daniela Engert <dani_at_[hidden]>
Date: Thu, 21 Apr 2022 07:50:09 +0200
Am 20.04.2022 um 22:51 schrieb Tom Honermann via SG15:
> Let's consider a simple example (apologies if I'm behind the times
> when it comes to the most current compiler options available; I'd love
> to be informed if there are better options available)
> $ cat t.cpp
> import M;
> int main() {
> f_from_m();
> }
> $ cat m.cppm
> export module M;
> export void f_from_m() {}
> Gcc's driver is able to produce an executable with a single invocation
> so long as m.cppm appears on the command line before t.cpp. Nico
> explicitly stated he is accepting of such a restriction and so am I.
> The following example successfully creates a module cache directory
> (gcm.cache) containing a BMI (M.gcm) that is then used to compile
> t.cpp and produce an executable (t). This suffices for me so long as
> gcc will also handle a modularized standard library (I have no idea
> what is planned for that).
> $ gcc -x c++ -std=c++20 -fmodules-ts m.cppm t.cpp -o t
> As far as I know, Clang and MSVC both require multiple compiler
> invocations for the above example. For Clang it is necessary to
> prebuild the BMI, the both reference it as a BMI and compile it.
> $ clang -std=c++20 --precompile m.cppm
> $ clang -std=c++20 -fmodule-file=m.pcm m.pcm t.cpp -o t
> Likewise, for MSVC:
> $ cl /std:c++latest /c /TP /interface m.cppm
> $ cl /std:c++latest /reference m.ifc m.obj t.cpp /Fet.exe
Thanks Tom. This happens to be the perfect example in regards to the
original topic that Nico brought up. If you change the extension of the
PMIU from .cppm to .ixx, then MSVC behaves the same as gcc and

$ cl /std:c++latest m.ixx t.cpp /Fet.exe

compiles and links. This works with more than one module on the same
command line as well as long as the file order fulfills the dependency
requirements (I assume the same is true with gcc and a future clang).
The only difference is that (by default) the current directory serves as
module cache directory. The behaviour and the results are just the same.


Received on 2022-04-21 05:50:14