2012-12-13 150 views
3

我一直在運行一些boost教程和它的庫。在Linux上編譯boost asio時鏈接錯誤

我通過基本教程跑了提升:

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 

它看起來像鏈接錯誤,但我包括相同的路徑前:假設你

/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 
+5

你需要-lpthread和-lboost_system-(具體什麼系統),也許-lboost_signals-(一些系統specifc) – frankc

+0

當你說具體的系統,如果我要在Windows上編譯它,我不得不改變查找窗口equivilant? – Jeff

+0

我的意思是像系統庫將被命名爲libboost_system-gcc41-mt.so。我甚至不知道它在窗口上的外觀 – frankc

回答

11

g++ -I /usr/local/boost_1_52_0 test.cpp -o example 

錯誤已經在/usr/lib目錄中安裝了增強庫並在/usr/include/boost中增加了頭文件,並且您已將代碼保存在名爲daytime1.cpp的文件中,您必須使用下面的命令來編譯源代碼已鏈接到:

$ g++ daytime1.cpp -o daytime -L /usr/lib/ -lboost_system -lboost_thread -lpthread