【发布时间】:2021-02-06 13:24:57
【问题描述】:
我正在尝试使用一些新的 c++20 功能,但我什至无法编译一些简单的代码行.. 我在 macOS 上工作,首先尝试使用 C++2a 语言方言在 Xcode 中编译它,但没有成功,然后尝试使用 g++ 从命令行编译代码,但我遇到了类似的错误。 一切都是最新的(Clang Vers 12,g++/gcc vers 10),我知道某些功能仍然存在一些问题。
所以这里是一个例子:
import <iostream>;
#include <vector>
int main(){
std::vector<int> vec{1,2,3};
for (int e : vec) std::cout << e << std::endl;
}
编译:
g++ -std=c++2a -fmodules-ts test.cpp
抛出以下错误:
header file <iostream> (aka '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream') cannot be imported because it is not known to be a header
所以我认为工具链中的标头路径存在问题,该路径没有最新更新,因此我尝试将路径更改为 g++ 主包含。 所以我尝试了:
g++ -std=c++2a -fmodules-ts -I/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/ test.cpp
哪个抛出了这个错误:
test.cpp:1:8: error: header file <iostream> (aka '/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/iostream') cannot be imported because it is not known to be a header unit
import <iostream>;
^
In file included from test.cpp:2:
In file included from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/vector:60:
/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/bits/stl_algobase.h:59:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
2 errors generated.
有人可以帮忙吗? 我知道我可以使用#include 进行编译 - 这只是作为使用新功能的示例 - 我遇到了同样的问题,例如进口 。 我真的很难对任何东西进行排序——哪个编译器是 c++20 的最佳用例,我如何以及在哪里可以包含/找到支持 c++20 的标准库? 以及如何在 Xcode 中一起使用所有内容?
【问题讨论】: