title: How to use c++20 modules with GCC?
body: <p>I'm currently trying the new C++20's feature called <strong>modules</strong> as described <a href="https://en.cppreference.com/w/cpp/language/modules" rel="noreferrer">here</a> using GCC 10.1.0, however if i try to build the following snippet of code the compiler throw me a bunch of errors.</p>
  <p>This is the snippets i wrote so far:</p>
  <pre class="lang-cpp prettyprint-override"><code>// helloworld.cpp
  export module helloworld;  // module declaration
  import &lt;iostream&gt;;         // import declaration
   
  export void hello() {      // export declaration
      std::cout &lt;&lt; &quot;Hello world!\n&quot;;
  }
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>// main.cpp
  import helloworld;  // import declaration
   
  int main() {
      hello();
  }
  </code></pre>
  <p>I'm compiling it using <code>g++ helloworld.cpp main.cpp -std=c++20</code>.</p>
  <p>The compiler gave me this error:</p>
  <pre><code>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 &lt;iostream&gt;;         // 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 &lt;iostream&gt;;         // 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 &lt;&lt; &quot;Hello world!\n&quot;;
        |          ^~~~
  helloworld.cpp:1:1: note: ‘std::cout’ is defined in header ‘&lt;iostream&gt;’; did you forget to ‘#include &lt;iostream&gt;’?
    +++ |+#include &lt;iostream&gt;
      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();
        |     ^~~~~
  </code></pre>
  <p>What i'm doing wrong?</p>