Does g++ support c++20 modules?

Hi,

I have tried the following command line:

1
2
3
4
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 ...)

Regards,
Juan
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:

https://en.cppreference.com/w/cpp/compiler_support/20

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.

https://en.cppreference.com/w/cpp/compiler_support/23

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, https://blog.feabhas.com/2021/08/c20-modules-with-gcc11/
There is a compiler flag:
g++ -c -std=c++20 -fmodules-ts func.cxx

Maybe that flag will make things works better.

https://gcc.gnu.org/projects/cxx-status.html
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

https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Modules.html

cmake c++ modules
https://devblogs.microsoft.com/cppblog/cpp20-modules-in-cmake-with-vs/

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++
https://winlibs.com/
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.

Topic archived. No new replies allowed.