问题
I've been trying to code something using the new experimental feature "modules-ts" that will be included in c++20. I've cloned the gcc branch (found here: https://gcc.gnu.org/wiki/cxx-modules), and I'm trying to follow that tutorial (on the link) using modules-ts but an g++ error is preventing me from doing that:
g++: error: unrecognized command-line option ‘-fmodules-ts’
I tried to see the version of g++, to make sure that is not reading from another previous version. And the answer is:
g++ (GCC) 10.0.0 20191029 (experimental) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Here is the command that I'm trying to run:
g++ -fmodules-ts hello.cppm main.cpp
回答1:
Modules-ts is not merged into GCC's main branch yet. You need to download GCC's source and compile it yourself, for further instructions see GCC's installation guide. Grab the source using
svn co svn://gcc.gnu.org/svn/gcc/branches/c++-modules SomeLocalDir
instead of
svn checkout svn://gcc.gnu.org/svn/gcc/trunk SomeLocalDir
and you'll get the correct version.
EDIT: For clarification, in this answer I assumed the OP did not compile the right GCC version because there is no svn revision number inside his gcc --version.
来源:https://stackoverflow.com/questions/58712244/how-to-compile-c-code-using-modules-ts-and-gcc-experimental