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
andapp.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”
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
- Module Partition Not Found: The compiler throws
error C7621
for bothvector3d
andpoint3d
. - 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?