Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
924 views
in Technique[技术] by (71.8m points)

c++ - 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;
question from:https://stackoverflow.com/questions/65943019/g10-c20-boost-1-75-0-error-awaitable-has-not-been-declared-in-boost

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...