boost中g++ 链接undefined reference to `boost::system::generic_category()问题

孤人 提交于 2019-12-04 06:30:02

编译错误如下:

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, 问题解决。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!