编译错误如下:
g++ -std=c++11 tcp_session.cpp tcp_server.cpp test.cpp -o test -pthread
/tmp/ccv4rZkD.o: In function `__static_initialization_and_destruction_0(int, int)':
tcp_session.cpp:(.text+0x670): undefined reference to `boost::system::generic_category()'
tcp_session.cpp:(.text+0x67c): undefined reference to `boost::system::generic_category()'
tcp_session.cpp:(.text+0x688): undefined reference to `boost::system::system_category()'
/tmp/ccv4rZkD.o: In function `boost::system::error_code::error_code()':
tcp_session.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccv4rZkD.o: In function `boost::asio::error::get_system_category()':
tcp_session.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `tcp_server::start_accept()':
tcp_server.cpp:(.text+0x18e): undefined reference to `tcp_session::socket()'
/tmp/cctVI799.o: In function `__static_initialization_and_destruction_0(int, int)':
tcp_server.cpp:(.text+0x2fc): undefined reference to `boost::system::generic_category()'
tcp_server.cpp:(.text+0x308): undefined reference to `boost::system::generic_category()'
tcp_server.cpp:(.text+0x314): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `boost::thread_exception::thread_exception(int, char const*)':
tcp_server.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): undefined reference to `boost::system::system_category()'
/tmp/cctVI799.o: In function `boost::condition_error::condition_error(int, char const*)':
添加链接库 -lboost_system, 问题解决。