2

我正在尝试编译一个包含#include <coroutine>头文件的程序。但是gcc10会抛出错误

/usr/include/c++/10/coroutine:295:2: error: #error "the coroutine header requires -fcoroutines"
  295 | #error "the coroutine header requires -fcoroutines"

我在 cmake 中设置了所有必要的标志

cmake_minimum_required(VERSION 3.17)
project(cortest1)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "-fcoroutines")
set(CMAKE_CXX_FLAGS "-pthread")

add_executable(cortest1 main.cpp)

但是编译器看不到 -fcoroutines 标志。我正在使用 g++ 10.2.0

4

1 回答 1

2
set(CMAKE_CXX_FLAGS "-pthread")

将标志设置为 -pthread 后,它不再具有以前具有协程标志的值。

PS 使用特定于目标的配置,即不要设置 CMAKE_CXX_FLAGS。请改用 target_compile_options。并使用 target_compile_features 而不是设置 CMAKE_CXX_STANDARD。

于 2021-01-02T16:00:00.453 回答