#include <boost/asio.hpp>
#include <iostream>
void handler(const boost::system::error_code &ec) {
std::cout << "5 s." << std::endl;
}
int main() {
boost::asio::io_service io_service;
boost::asio::deadline_timer timer(io_service,
boost::posix_time::seconds(5));
timer.async_wait(handler);
io_service.run();
return 0;
}
g++ timer.cc
/tmp/cc6rBUr7.o:在函数‘__static_initialization_and_destruction_0(int, int)’中:
timer.cc:(.text+0x12f):对‘boost::system::generic_category()’未定义的引用
timer.cc:(.text+0x13b):对‘boost::system::generic_category()’未定义的引用
timer.cc:(.text+0x147):对‘boost::system::system_category()’未定义的引用
/tmp/cc6rBUr7.o:在函数‘boost::system::error_code::error_code()’中:
timer.cc:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17):对‘boost::system::system_category()’未定义的引用
/tmp/cc6rBUr7.o:在函数‘boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const’中:
timer.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8):对‘boost::system::generic_category()’未定义的引用
timer.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3):对‘boost::system::generic_category()’未定义的引用
/tmp/cc6rBUr7.o:在函数‘boost::system::error_category::std_category::equivalent(std::error_code const&, int) const’中:
timer.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8):对‘boost::system::generic_category()’未定义的引用
timer.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3):对‘boost::system::generic_category()’未定义的引用
timer.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1d2):对‘boost::system::generic_category()’未定义的引用
/tmp/cc6rBUr7.o:在函数‘boost::asio::error::get_system_category()’中:
timer.cc:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5):对‘boost::system::system_category()’未定义的引用
collect2: error: ld returned 1 exit status