Issues with C++ Modules and Partitions: "Module partition 'vector3d' for module unit 'app.geometry' was not found"

Hi everyone,

I’m encountering a persistent issue while working with C++ modules and partitions in a CMake-based project. The errors appear during the build process using MSVC and Visual Studio generators. Here are the relevant details and errors:

error C7621: module partition 'vector3d' for module unit 'app.geometry' was not found
error C7621: module partition 'point3d' for module unit 'app.geometry' was not found
error C2653: 'geometry': is not a class or namespace name
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I have the following setup:

  • Module Unit: app.geometry.ixx

  • Partitions: app.geometry:vector3d and app.geometry:point3d

  • Each partition has its own implementation file (e.g., vector3d.cpp, point3d.cpp).

  • The CMake target includes both the .ixx files and the .cpp files for the partitions.

  • Windows

  • Visual Studio MSVC 19.42.34435.0

  • -G “Visual Studio 17 2022”

  • GitHub - Brunner246/modules_partition

target_sources(${PROJECT_NAME}
    PUBLIC
        FILE_SET CXX_MODULES
        BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
        FILES
            app.geometry.ixx
            app.geometry-vector3d.ixx
            app.geometry-point3d.ixx
    PRIVATE
        app.geometry-vector3d.cpp
        app.geometry-point3d.cpp
)

Partition composition

export module app.geometry;

export import :vector3d;
export import :point3d;

Partition for vector3d

// pathFinder.app.geometry-vector3d.ixx
export module app.geometry:vector3d;

export namespace geometry {
    class Vector3D {
    public:
        Vector3D(double x, double y, double z);
    };
}

//pathFinder.app.geometry-vector3d.cpp
module app.geometry:vector3d;
import :vector3d;

namespace geometry {
    Vector3D::Vector3D(double x, double y, double z) : x(x), y(y), z(z) {}
}

Partition for point3d

// pathFinder.app.geometry-point3d.ixx
export module pathFinder.app.geometry:point3d;

export namespace geometry {
    class Point3D {
    public:
        Point3D(double x, double y, double z);
    };
}
// pathFinder.app.geometry-point3d.cpp
module pathFinder.app.geometry:point3d;
import :point3d;

geometry::Point3D::Point3D(double x, double y, double z)
    : x(x), y(y), z(z) {}

Issues

  1. Module Partition Not Found: The compiler throws error C7621 for both vector3d and point3d.
  2. Type and Namespace Errors: The compiler claims that 'geometry' is not a valid namespace or class.

Is there a specific way CMake expects partitions and their implementation files to be declared or linked together?

if i add the files wihthout FILE_SET, it works.

target_sources(${PROJECT_NAME}
        PUBLIC
        pathFinder.app.geometry-vector3d.ixx
        pathFinder.app.geometry-point3d.ixx
        pathFinder.app.geometry.ixx
        PRIVATE
        pathFinder.app.geometry-vector3d.cpp
        pathFinder.app.geometry-point3d.cpp
)

If I use the Ninja generator I get this error:

on.dir\CXX.dd.rsp
CMake Error: Circular dependency detected in the C++ module import graph. See modules named: "app.geometry", "app.geometry:point3d", "app.geometry:vector3d"
ninja: build stopped: subcommand failed.

Implementation files should never have partition names. There is a Microsoft-specific extension for it, but it is wholly unnecessary. Basically, remove the :vector3d and :point3d from the .cpp files.

Hi @ben.boeckel

Please see following comment on the need for import :foo https://resharper-support.jetbrains.com/hc/en-us/community/posts/9355770978834-Resharper-C-20-module-support-wants-to-add-forward-declaration?page=1#community_comment_9400220709906

i am using CLion, if i comment out import :vector3d, Resharper does not find the interface file anymore.

When I remove the partition imports and compile, i get following errors

error C2653: 'geometry': is not a class or namespace name [D:\source\modules\cmake-build-debug\modules_partition.vcxproj]
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [D:\source\modules\cmake-build-debug\modules_partition.vcxproj]