剛剛開始使用boost線程的多線程;我有一個Hello World類型的程序在鏈接到線程庫期間失敗。以下是終端窗口輸出:C++鏈接失敗,未定義引用libboost_thread
g++ -Wall -I/usr/include HelloWorld.cpp -L/usr/local/lib -pthread -lboost_thread -lrt -lboost_system
/tmp/ccTKHnfd.o: In function `main':
HelloWorld.cpp:(.text+0x4a): undefined reference to `boost::thread::join()'
HelloWorld.cpp:(.text+0x5b): undefined reference to `boost::thread::~thread()'
HelloWorld.cpp:(.text+0x70): undefined reference to `boost::thread::~thread()'
/tmp/ccTKHnfd.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':
HelloWorld.cpp: (.text._ZN5boost6threadC2IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[_ZN5boost6threadC5IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE]+0x23): undefined reference to `boost::thread::start_thread()'
collect2: ld returned 1 exit status
我用aptitude安裝升壓開發庫1.48,相信我使用所有正確的標誌編譯器。我錯過了什麼?我的gcc是4.6.3。在此先感謝您的幫助
如果找不到庫,則只能有2個原因:1)缺少庫的路徑; 2)庫名稱不正確。檢查兩個,你會成功。/usr/local/lib中確實存在boost_thread嗎? – 2013-02-20 08:48:44