I have a very simple project where I’m trying to learn how to use modules in C++20:
> tree
.
├── foo_something.cxx
└── main.cxx
1 directory, 2 files
main.cxx
:
import <iostream>;
import foo.something;
int main() {
std::cout << "Hin";
}
foo_something.cxx
:
export module foo.something;
import <format>;
import <chrono>; // This seems to cause the issue
int hi() {
return 5;
}
And I’m building this with:
g++ -std=c++20 -fmodules-ts -x c++-system-header format -x c++-system-header chrono -x c++-system-header iostream
g++ -std=c++20 -fmodules-ts -c foo_something.cxx
g++ -std=c++20 -fmodules-ts main.cxx
On the last command though, I get this weird error:
> g++ -std=c++20 -fmodules-ts main.cxx
‘
/usr/include/c++/13/format:2862: confused by earlier errors, bailing out
If I comment out the import <chrono>
in foo_something.cxx, it builds and runs fine.
My questions are:
- Is it expected than a completely unused module import can affect the compilation?
- What specifically is going wrong?
In case it’s relevant:
> g++ --version
g++ (SUSE Linux) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.