ubuntu中编译boost::asio出现下面错误
#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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问