【发布时间】:2021-11-19 14:08:25
【问题描述】:
我为系统头文件一一创建预编译头文件
$ g++ -fmodules-ts -std=c++20 -x c++-system-header concepts
$ g++ -fmodules-ts -std=c++20 -x c++-system-header limits
$ g++ -fmodules-ts -std=c++20 -x c++-system-header iostream
我将所需的系统标头收集到 Reverse 中
$ cat Reverse
import <concepts>;
import <limits>;
import <iostream>;
$ g++ -fmodules-ts -std=c++20 -x c++-header Reverse
$ ls gcm.cache/,
Reverse.gcm
我尝试导入模块头
$ head Reverse.cpp
import <Reverse>;
$ make
g++ -fmodules-ts -std=c++20 -I./ -o Reverseexec Reverse.cpp
In module imported at Reverse.cpp:4:1:
./Reverse: error: failed to read compiled module: Bad file data
./Reverse: note: compiled module file is ‘gcm.cache/,/Reverse.gcm’
./Reverse: fatal error: returning to the gate for a mechanical issue
compilation terminated.
make: *** [Makefile:2: Reverseexec] Error 1
我更改了 Reverse.cpp 中的导入并编译
$ head Reverse.cpp
import <concepts>;
import <limits>;
import <iostream>;
$ make
g++ -fmodules-ts -std=c++20 -o Reverse Reverse.cpp
我发现了一个似乎相关的错误。
[Bug c++/98944] [modules] 无法读取未导出分区的已编译模块。
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/11/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-
11.2.0/configure --srcdir=/mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-11.2.0
--prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --
docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --
build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin -
-without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --
with-gcc-major-version-only --enable-shared --enable-shared-libgcc --
enable-static --enable-version-specific-runtime-libs --enable-bootstrap --
enable-__cxa_atexit --with-dwarf2 --with-tune=generic --disable-bootstrap
--enable-languages=c,c++,fortran,lto,objc,obj-c++,jit --enable-graphite --
enable-threads=posix --enable-libatomic --enable-libgomp --enable-
libquadmath --enable-libquadmath-support --disable-libssp --enable-libada
--disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-
include=/usr/include/cloog-isl --without-libiconv-prefix --without-
libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-
libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
我做错了什么?为什么我会收到错误消息,
g++ -fmodules-ts -std=c++20 -I./ -o Reverseexec Reverse.cpp
In module imported at Reverse.cpp:4:1:
./Reverse: error: failed to read compiled module: Bad file data
./Reverse: note: compiled module file is ‘gcm.cache/,/Reverse.gcm’
./Reverse: fatal error: returning to the gate for a mechanical issue
compilation terminated.
make: *** [Makefile:2: Reverseexec] Error 1
【问题讨论】:
-
模块的 GCC 实现仍然有很多错误。有一个与将标准标题作为标题单元导入有关的问题的元错误:gcc.gnu.org/bugzilla/show_bug.cgi?id=99227。遗憾的是,GCC 的模块开发目前处于中断状态。如果您的错误与元错误中列出的不同,请报告您的错误。