如何使用g ++在c ++ 20中使用模块?

问题描述

我阅读了此链接 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++ 部分支持它,还有其他方法可以使用它吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...