C++ Logo

sg15

Advanced search

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

From: Nicolai Josuttis <nico_at_[hidden]>
Date: Thu, 21 Apr 2022 10:13:58 +0200
Am 21.04.2022 um 08:09 schrieb Tom Honermann via Ext:
>
>> On Apr 21, 2022, at 1:50 AM, Daniela Engert <dani_at_[hidden]> wrote:
>>
>> 
>> 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.
>>
> Thank you, Dani! I was somehow under the impression that /interface
> was still needed for the .ixx extension. Thanks for the correction!

In VC++, only /internalPartition is an option you cannot skip by any suffix.


-- 
--- 
Nicolai M. Josuttis
www.josuttis.de
+49 (0)531 / 129 88 86
+49 (0)700 / JOSUTTIS
Books:
 C++: http://cppstd20.com, http://cppstd17.com, http://cppmove.com,
      http://cppstdlib.com, http://tmplbook.com

Received on 2022-04-21 08:14:04