2

cppreference gives an example of a module partition implementation unit (A-C.cpp) being used without having to define a interface unit alongside it:

/////// A-B.cpp   
export module A:B;
...
 
/////// A-C.cpp
module A:C;
...
 
/////// A.cpp
export module A;
 
import :C;
export import :B;
 
...

However, in my code - compiled with MSVC - the first example works, but the second doesn't:

/////// game.ixx
export module game;

import :rendering;

...

/////// rendering.ixx
export module game:rendering;  // this works

...

vs

/////// game.ixx
export module game;

import :rendering;

...

/////// rendering.cpp
module game:rendering;  // this doesn't work

...

From what I understand, removing the export declaration in rendering.ixx (and changing the extension back to .cpp for MSVC, but I tried both) turns that partition into a implementation unit, which is something I want to do because I want to keep my rendering functions internal. However, I get a "module partition 'rendering' for module unit 'game' was not found" error when I do that.

(Also, this is tangential but why doesn't game.ixx throw an error because I didn't export-import the :rendering partition in game.ixx? cppreference says:)

Module partitions can be module interface units (when their module declarations have export). They must be export-imported by the primary module interface unit, and their exported statements will be visible when the module is imported.

1 Answer 1

1

It's unclear what you mean by "without having to define a interface unit alongside it" because there is an interface unit defined. The primary module interface is right there.

The problem is that you're not creating partitions in accord with Visual studio's expectations. If a module unit is an implementation partition, you should give it the .ixx extension. Failing that, you can use the \internalPartition compiler option for that file.

8
  • To clarify, I'm talking about the case where someone wants to add a new module partition and separate the interface and implementation units of that partition (without drawing from the primary module interface, which I agree works in principle but may not scale well). And I also think that the Visual Studio extension naming maybe is not the most intuitive, but according to Microsoft, "Module unit implementation files don't end with an .ixx extension--they're normal .cpp files."
    – jwick
    Commented Jun 29 at 5:09
  • @jwick: "without drawing from the primary module interface" What does that mean? If it's an interface unit, then it is part of the "primary module interface". "according to Microsoft" That tutorial doesn't talk about implementation partitions, just interface partitions. Commented Jun 29 at 19:34
  • Yes, I understand that interface units are all technically part of the primary module interface. I'm talking about when you want to add new interface/implementation files for a new partition that you're working on - is that not a common scenario? Forcing multiple collaborators to work in the same primary module interface can get organizationally messy, isn't forestalling that one of the main benefits of module partitions?
    – jwick
    Commented Jun 29 at 23:42
  • From that tutorial: "The naming convention for the module partition's implementation file follows the naming convention for a partition. But it has a .cpp extension because it's an implementation file."
    – jwick
    Commented Jun 30 at 4:39
  • @jwick: I can't help what the tutorial says. All I can tell you is what the actual MSVC documentation says. And it says that implementation partition units need to use the .ixx extension or the given compile option. Commented Jun 30 at 16:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.