编译时候遇到的问题:
/usr/bin/ld: /tmp/ccljkSgY.o: in function `__static_initialization_and_destruction_0(int, int)':
ASIO.cpp:(.text+0x146): undefined reference to `boost::system::generic_category()'
/usr/bin/ld: ASIO.cpp:(.text+0x152): undefined reference to `boost::system::generic_category()'
/usr/bin/ld: ASIO.cpp:(.text+0x15e): undefined reference to `boost::system::system_category()'
/usr/bin/ld: /tmp/ccljkSgY.o: in function `boost::system::error_code::error_code()':
ASIO.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x1b): undefined reference to `boost::system::system_category()'
/usr/bin/ld: /tmp/ccljkSgY.o: in function `boost::asio::error::get_system_category()':
ASIO.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x9): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
最可能出现的问题是:编译语句没有加上 -lboost_system
g++ -std=c++14 -o main main1.cpp -lboost_system
但是还有一个比较坑爹的是:即使加上了也报错。
排除了一会儿,才发现装了两个版本的boost,当删除一个时,恢复了正常。
并且值得注意的是,当用到了多线程时,还需要加上 -lpthread。
g++ -std=c++14 -o main main1.cpp -lboost_system -lpthread
特此记录,方便查阅。