c++ - 是 clang-11 的调用通过 -fcoroutines 标志标头?
问题描述
我正在尝试编译一个 .cpp 文件,该文件使用该coroutine
库的命令。
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp
我收到这样的错误:
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/coroutine:295:2: error: "the coroutine header requires -fcoroutines"
#error "the coroutine header requires -fcoroutines"
所以,我添加了标志:
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp -fcoroutines
现在,我得到了错误:
clang-11: error: unknown argument: '-fcoroutines'
这是一个错误吗?
最接近的问题在这里。但是,我无法断定是否存在错误。
对于它的价值,这里是来源:
#include <iostream>
#include <coroutine>
template<typename T>
bool is_prime(T number) {
for(int i=2;i<number;i++) {
if (not i%number) return true;
}
return false;
}
class prime_iterator {
unsigned int number = 2;
public:
auto operator*() const {
return number;
}
prime_iterator& operator++() {
++number;
if (not is_prime(number)) {
co_yield number; // Trying to invoke co_yield just to see if library works.
}
return *this;
}
};
auto main() -> int {
for(prime_iterator p; *p < 30; ++p) {
std::cout << *p << " is prime";
}
}
解决方案
对于 clang,它应该是 -fcoroutines-ts。除非您使用与 libstdc++ 混合的 clang 构建协程。
推荐阅读
- python-3.x - 从停用词中清除多个术语
- python - tf.keras.layers.Conv3DTranspose 在输入动态形状时抛出 TypeError
- html - 如何在 Symfony 4 表单中的输入上添加占位符?
- python - 删除对象而不刷新django
- amazon-web-services - 对 S3 存储桶中新对象的 PUTS 写后读一致性的警告
- javascript - 当输入、选择等形式发生变化时如何获取计数器?
- node.js - 如何在线正确上传 localhost 网站?
- powershell - 如何比较文件中的两个连续字符串
- cordova - Ionic 4 不能在没有 cordova 的情况下使用 HTTP 插件了吗?
- sql - SQL doesn't display rows where