我有以下文件: Testing2.cpp:
#include <string>
#include <iostream>
int main() {
std::string ss = "aaaa";
ss += "aa";
std::cout << ss << "\n";
}当我像这样编译它:g++-11 -o Testing2 Testing2.cpp -std=c++20时,我得到了想要的输出。当我像这样编译它:g++-11 -o Testing2 Testing2.cpp -std=c++20 -fmodules-ts时,我会得到一个运行时段错误。
问题1:这是g++中的一个bug,还是我遗漏了什么?
我有几个类似的问题,一个与std::filesystem有关,一个与std::map有关。即使没有实际使用模块,代码也不能正常工作。
问题2:上面的代码甚至不使用模块。为什么g++在启用-fmodules ts``时与未启用时编译它的方式不同?
任何见解都是受欢迎的。
发布于 2022-05-02 07:37:19
事实证明,g++将使用预编译的标准库模块,如果可用的话(位于gcm.cache文件夹中),在这两种情况下:#include <string>和import <string>;。
通过从gcm.cache目录中删除string和iostream模块并重新编译它们,解决了我的问题(我使用了命令g++-11 -std=c++20 -fmodules-ts -c -x c++-system-header string)。
https://stackoverflow.com/questions/72076421
复制相似问题