我阅读了此链接https://gcc.gnu.org/wiki/cxx-modules并尝试从该网站复制以下示例。我已经知道这个编译器部分支持模块系统。(注:我用的是windows)
// hello.cc
module;
#include <iostream>
#include <string_view>
export module hello;
export void greeter(std::string_view const &name) {
std::cout << "Hello " << name << "!\n";
}
// main.cc
import hello;
int main() {
greeter("world");
return 0;
}
// Should print "Hello world!"
我目前有GCC 11.0.1快照并尝试使用以下参数编译这些文件:
g++ -std=gnu++2b -Wall -fmodules-ts hello.cc main.cc
编译器给了我这些错误:
hello.cc:6:8: internal compiler error: in get_cxx_dialect_name, at cp/name-lookup.c:7027
6 | export module hello;
| ^~~~~~
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
In module imported at main.cc:1:1:
hello: error: failed to read compiled module: No such file or directory
hello: note: compiled module file is 'gcm.cache/hello.gcm'
hello: note: imports must be built before being imported
hello: fatal error: returning to the gate for a mechanical issue
compilation terminated.
如果我先编译hello.cc
,那么编译器仍然给出错误:
C:\...\hello.cc | 6 | error: failed to write compiled module: No such file or directory |
C:\...\hello.cc | 6 | note: compiled module file is 'gcm.cache/hello.gcm' |
- 我应该怎么办?
- 我应该等待对 g++ 模块的完全支持吗?
- 即使 g++ 部分支持它,还有其他方法可以使用它吗?