【发布时间】:2012-12-13 15:53:42
【问题描述】:
我已经浏览了一些关于 boost 及其库的教程。
我浏览了 boost 的基本教程:
http://www.boost.org/doc/libs/1_52_0/more/getting_started/unix-variants.html
而且效果很好。我对 asio 教程有疑问:
http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/tutorial/tutdaytime1/src.html
它看起来像链接错误,但我包含与以前相同的路径:
g++ -I /usr/local/boost_1_52_0 test.cpp -o example
错误:
/tmp/cce4EZME.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x57b): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x587): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x593): undefined reference to `boost::system::system_category()'
/tmp/cce4EZME.o: In function `boost::system::error_code::error_code()':
test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/cce4EZME.o: In function `boost::asio::error::get_system_category()':
test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/cce4EZME.o: In function `boost::asio::detail::posix_thread::~posix_thread()':
test.cpp:(.text._ZN5boost4asio6detail12posix_threadD2Ev[_ZN5boost4asio6detail12posix_threadD5Ev]+0x26): undefined reference to `pthread_detach'
/tmp/cce4EZME.o: In function `boost::asio::detail::posix_thread::join()':
test.cpp:(.text._ZN5boost4asio6detail12posix_thread4joinEv[_ZN5boost4asio6detail12posix_thread4joinEv]+0x2b): undefined reference to `pthread_join'
/tmp/cce4EZME.o: In function `boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
test.cpp:(.text._ZN5boost4asio6detail12posix_thread12start_threadEPNS2_9func_baseE[_ZN5boost4asio6detail12posix_thread12start_threadEPNS2_9func_baseE]+0x29): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
【问题讨论】:
-
你需要 -lpthread 和 -lboost_system-(系统特定的东西),也许 -lboost_signals-(系统特定的东西)
-
当你说系统特定时,如果我要在 windows 上编译它,我必须更改 find windows equivilant?
-
我的意思是系统库将被命名为 libboost_system-gcc41-mt.so 之类的名称。我什至不知道它在 windows 上是什么样子的
-
在 Windows 上 boost 使用自动链接,因此您通常不必担心
标签: c++ ubuntu boost-asio