【问题标题】:Why doesn't gcc10 see the -fcoroutines flag?为什么 gcc10 看不到 -fcoroutines 标志?
【发布时间】:2021-04-08 22:22:04
【问题描述】:

我正在尝试编译一个包含#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

【问题讨论】:

  • 使用make VERBOSE=1查看实际命令;这看起来像一个 cmake 配置错误
  • set 设置。它不附加。

标签: c++ coroutine c++20 gcc10


【解决方案1】:
set(CMAKE_CXX_FLAGS "-pthread")

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

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

【讨论】:

    猜你喜欢
    • 2021-02-18
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多