2

I am trying to compile a program with #include <coroutine> header file included in it. But gcc10 throws an error

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

I set all the necessary flags in 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)

But the compiler doesn't see the -fcoroutines flag. I am using g ++ 10.2.0

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Anton
  • 275
  • 1
  • 9

1 Answers1

2
set(CMAKE_CXX_FLAGS "-pthread")

After you set the flags to -pthread, it no longer has the previous value that had the coroutine flag.

P.S. Use target specific configuration i.e. don't set CMAKE_CXX_FLAGS. Use target_compile_options instead. And use target_compile_features instead of setting CMAKE_CXX_STANDARD.

eerorika
  • 232,697
  • 12
  • 197
  • 326