Does g++ support c++20 modules?


I have tried the following command line:

Q:\c++\g++> g++ -std=c++20 -fmodules-ts  -o main.exe  main.cpp  .\new_module.ixx
Q:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:.\new_module.ixx: file format not recognized; treating as linker script
Q:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:.\new_module.ixx:2: syntax error
collect2.exe: error: ld returned 1 exit status

the files are main.cpp and new_module.ixx (contains export module ...)

When in doubt about a certain C++ core language or library feature being implemented it is recommended to check the compiler support section of cppreference.

Regarding C++20 supported features:

The only compiler that currently supports C++20 modules is MSVC, the rest either are partial support or not at all.

The latest officially released standard is C++23, C++23 support from GCC shows they are in the lead currently.

Yet again you ask a question that you could (and should) have been able to answer on your own with a bit of work. Learn to be self-sufficient.
To be fair, that is referring to the mainline gcc project, and not distributions like mingw. And, "partial" support is pretty ambiguous, so it takes a lot more digging to know what kind of support mingw64 12.2.0 has for modules.

I did happen to find this link,
There is a compiler flag:
g++ -c -std=c++20 -fmodules-ts func.cxx

Maybe that flag will make things works better.
Last edited on
but I have this in my sample:

g++ -std=c++20 -fmodules-ts  -o main.exe  main.cpp  .\new_module.ixx

and it does not compile/link
GeorgeP how do you know if I have been looking all over in internet?

But Ganado has given me the complete and correct answer without the lecture

Thanks Ganado!!
Weird, I read the post like twice but didn't see that you already had that flag enabled.
I have no idea, then. [other than devs just haven't done it yet]
Last edited on
I searched for:

g++ modules

cmake c++ modules

Isn't the *.ixx convention a MS thing? g++ has a different convention, IIRC it's mandatory?

Also, trying to do *new* stuff with mingw is asking for trouble? Try with Linux g++.

I hope this helps :+)

Here is my gcc/g++
I have 12.2, but I see I should update.
No problem using -std=c++20
These winlib for mingw are very easy to use.
You can put the bin folder on path if you like to have immediate access to the binaries.
Nothing to install and no registry changes for these, just the barebone compilers.
No need to define include directories whereabouts or config files.
If you use third party dll's or static libs then the switch -L(path to libs) find them.

Registered users can post here. Sign in or register to post.