Search code examples
c++boostcoroutineasioc++-coroutine

g++10, C++20, boost 1.75.0 :: error: 'awaitable' has not been declared in 'boost::asio'


I tried to compile the example: echo_server_with_as_single_default.cpp from boost examples on an:

  • ubuntu 18.04
  • boost 1.75.0
  • g++ 10.1.0

Using the following commands to compile&link (I know it's not optimal, I reused the makefile from another project I am working on):

g++ -MT bin/.o/src/main.o -MD -MP -MF bin/.d/src/main.d -std=c++20 -Isrc -Ilib/ -g -Wfatal-errors -c -o bin/.o/src/main.o src/main.cpp
g++ -o bin/server bin/.o/src/main.o  -lpthread -lrt -lboost_system -lboost_thread -lboost_chrono -lboost_context -lboost_coroutine -DBOOST_COROUTINES_NO_DEPRECATION_WARNING

And I get the following error:

I tried diferrent combinations but there is something I am missing. Any help?

error: 'awaitable' has not been declared in 'boost::asio'
   22 | using boost::asio::awaitable;

Solution

  • Currently, coroutines are not enabled by default in gcc. You need to pass the -fcoroutines compiler switch in order to enable them. This will probably change soon as it already works with the current gcc trunk version.

    See here (I had to comment out the code in main due to the execution time cap in godbolt.org).