C++ 如何使用c++;有GCC的20个模块?

C++ 如何使用c++;有GCC的20个模块?,c++,c++20,C++,C++20,我目前正在使用GCC10.1.0尝试新的C++20功能,名为modules,但是如果我尝试构建以下代码片段,编译器会给我带来一系列错误 以下是我到目前为止写的片段: //helloworld.cpp 导出模块helloworld;//模块声明 导入;//进口报关单 导出无效hello(){//导出声明 std::cout说它还不支持模块 对C++20的支持还不完整(考虑到我们已经到2020年了,这已经足够公平了!而且C++20在技术上还不存在……) 然而,有了一些标志和一个开发分支,您就可以使用

我目前正在使用GCC10.1.0尝试新的C++20功能,名为modules,但是如果我尝试构建以下代码片段,编译器会给我带来一系列错误

以下是我到目前为止写的片段:

//helloworld.cpp
导出模块helloworld;//模块声明
导入;//进口报关单
导出无效hello(){//导出声明
std::cout说它还不支持模块

对C++20的支持还不完整(考虑到我们已经到2020年了,这已经足够公平了!而且C++20在技术上还不存在……)

然而,有了一些标志和一个开发分支,您就可以使用正在进行的实现了——在上阅读更多关于它的信息


GCC 10中的默认语言版本是C++14;GCC 11将其升级到C++17。

我从23.1.21开始看到GNU GCC网站,它说你必须包含一个名为-fmodules ts的标志。这里是网站的链接,以获取更多信息

helloworld.cpp:2:1: warning: keyword ‘export’ not implemented, and will be ignored
    2 | export module helloworld;  // module declaration
      | ^~~~~~
helloworld.cpp:2:8: error: ‘module’ does not name a type
    2 | export module helloworld;  // module declaration
      |        ^~~~~~
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
    3 | import <iostream>;         // import declaration
      |         ^~~~~~~~
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:9: error: ‘iostream’ was not declared in this scope
helloworld.cpp:3:1: error: ‘import’ does not name a type
    3 | import <iostream>;         // import declaration
      | ^~~~~~
helloworld.cpp:5:1: warning: keyword ‘export’ not implemented, and will be ignored
    5 | export void hello() {      // export declaration
      | ^~~~~~
helloworld.cpp: In function ‘void hello()’:
helloworld.cpp:6:10: error: ‘cout’ is not a member of ‘std’
    6 |     std::cout << "Hello world!\n";
      |          ^~~~
helloworld.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
  +++ |+#include <iostream>
    1 | // helloworld.cpp
main.cpp:2:1: error: ‘import’ does not name a type
    2 | import helloworld;  // import declaration
      | ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:5:5: error: ‘hello’ was not declared in this scope
    5 |     hello();
      |     ^~~~~