使用 clang 编译 c++-20 模块时。导入一个导入另一个文件的文件时出现奇怪的编译错误,该文件又导入了第三个文件,如下所示:
// a.cppm
#include <string>
export module a;
export std::string getStuffA() {
return "a";
}
// b.cppm
#include <string>
import a;
export module b;
export std::string getStuffB() {
return "b" + getStuffA();
}
// c.cpp
#include <string>
import b;
int main() {
std::cout << getStuffB() << std::endl;
return 0;
}
编译器输出:
In file included from ./src/c.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ios:44:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_ios.h:37:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/locale_facets.h:2569:5: error: inline declaration of 'isspace' follows non-inline definition
它还列出了一些似乎同时具有内联和非内联定义的函数,例如 isprint、iscntrl、isupper。
有什么办法可以绕过这些错误。
注意:删除std::string
并#include <string>
删除编译错误,所以我认为错误来自<string>