簡體   English   中英

如何使用boost :: asio :: spawn構建程序

[英]How to build a program using boost::asio::spawn

如何構建使用boost lib的程序?

我無法建立使用boost::asio:spawn的示例。

  • G ++版本:7.3

  • Boost Lib版本:1.69

碼:

#include <iostream>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

int main ()
{
  boost::asio::io_service io_service;

  // Spawn coroutine.
  boost::asio::spawn(io_service,
    [&io_service](boost::asio::yield_context yield_context) {
      // Add more 'work' to the io_service.
      io_service.post([] {
        std::cout << "Other work" << std::endl;
      });

      // Wait on a timer within the coroutine.
      boost::asio::deadline_timer timer(io_service);
      timer.expires_from_now(boost::posix_time::seconds(1));
      std::cout << "Start wait" << std::endl;
      timer.async_wait(yield_context);
      std::cout << "Woke up" << std::endl;
    });

  io_service.run();
}

錯誤:

boost::asio::experimental::co_spawn has not been declared

我試圖重現您的問題,但不能(使用與您報告相同的版本)。

另請參閱Live Live Wandbox(GCC7.3 / boost1.69)

這是我用來構建的內容:

g++ -std=c++11 -pthread -I ~/custom/boost_1_69_0/ -L ~/custom/boost_1_69_0/stage/lib/ test.cpp -lboost_{thread,context,coroutine,system} -DBOOST_COROUTINES_NO_DEPRECATION_WARNING

這是bash oneliner的原因:

g++ -std=c++11 -pthread \\ -I /home/sehe/custom/boost_1_69_0/ \\ -L /home/sehe/custom/boost_1_69_0/stage/lib/ \\ test.cpp \\ -lboost_thread \\ -lboost_context \\ -lboost_coroutine \\ -lboost_system \\ -DBOOST_COROUTINES_NO_DEPRECATION_WARNING

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM