I have a C++ module that imports std:
// MyModule.ixx
export module MyModule;
import std;
export namespace MyNamespace {
class MyClass : std::monostate {};
}
I want to import the module in another file:
// main.cpp
#include <QtCore/QDebug>
import MyModule;
auto main(int argc, char **argv) -> int {
qDebug() << "test";
MyNamespace::MyClass A;
}
This gives a compilation error:
main.cpp(7,25): fatal error C1117: unrecoverable error importing module 'std': symbol 'monostate' has already been defined
If I remove #include <QtCore/QDebug> and qDebug() << "test";, the program compiles fine. So it seems that #include <QtCore/QDebug> indirectly includes std::monostate, and that it conflicts with the one imported by import std; in MyModule.ixx.
How can I resolve this? Can't I import std when somewhere else in my program the standard library is #included?
I solved it by importing <variant> instead of std:
// MyModule.ixx
export module MyModule;
import <variant>;
export namespace MyNamespace {
class MyClass : std::monostate {};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With