根据cppreference.com ( https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_features )的说法,自第8版以来,Clang一直部分支持C++20协同服务:

但是如果在Clang主干(即将发布的版本13)中,我会编写
#include <coroutine>它导致错误( https://gcc.godbolt.org/z/rTfjbarKz ):
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/coroutine:334:2: error: "the coroutine header requires -fcoroutines"
#error "the coroutine header requires -fcoroutines"如果我在命令行中添加了-fcoroutines标志,那么Clang ( https://gcc.godbolt.org/z/qMrv6nMzE ):
clang-13: error: unknown argument: '-fcoroutines'在Clang中有什么方法可以开始使用C++20协同吗?
发布于 2021-07-27 07:51:30
请注意,第一个错误出现在GCC标准库中,由此可以推断,-fcoroutines选项是GCC而不是Clang的。
要使用Clang libc++进行构建,您需要添加选项-stdlib=libc++。但这将导致找不到<coroutine>头文件。
由于coroutines仍然处于“实验性”阶段,所以您必须包括<experimental/coroutine>。
所以有两件事你需要改变:
(-stdlib=libc++)
#include <experimental/coroutine>)还请注意,由于协同是实验性的,因此头文件中定义的符号将位于std::experimental命名空间中。
https://stackoverflow.com/questions/68540816
复制相似问题