如何使用 boost::asio::spawn 构建程序
How to build a program using boost::asio::spawn
如何构建使用 boost 库的程序?
我无法构建使用示例 boost::asio:spawn
。
G++版本:7.3
增强库版本: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 On 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 单班机:
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
如何构建使用 boost 库的程序?
我无法构建使用示例 boost::asio:spawn
。
G++版本:7.3
增强库版本: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 On 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 单班机:
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