2013-04-03 152 views
0

我試圖在Qt中創建boost::thread應用程序。 這裏是我的代碼:Qt中未定義的boost :: thread引用

#include <iostream> 

#include "boost/thread.hpp" 
#include "boost/bind.hpp" 

using namespace std; 

class A { 
public: 
    void tf() { 
     for (int i = 0; i < 100; ++i) { 
      cout << i << endl; 
     } 
    } 
}; 

int main() 
{ 
    boost::shared_ptr<A> aPtr; 
    cout << "Hello World!" << endl; 
    boost::thread t = boost::thread(boost::bind(&A::tf, aPtr.get())); 
    cout << "Thread started" << endl; 
    return 0; 
} 

和相應的.pro文件:

TEMPLATE = app 
CONFIG += console 
CONFIG -= qt 

LIBS += -L"C:/Program Files (x86)/boost/boost_1_49/lib" 
DEPENDPATH += "C:/Program Files (x86)/boost/boost_1_49" 
INCLUDEPATH += "C:/Program Files (x86)/boost/boost_1_49" 

SOURCES += main.cpp 

當我嘗試編譯它,我得到:

{{path}}\main.cpp:21: error: undefined reference to `_imp___ZN5boost6threadD1Ev' 
{{path}}\main.o:-1: In function `ZN5boost6threadC1INS_3_bi6bind_tIvNS_4_mfi3mf0Iv1AEENS2_5list1INS2_5valueIPS6_EEEEEEEET_NS_10disable_ifINS_14is_convertibleIRSE_NS_6detail13thread_move_tISE_EEEEPNS0_5dummyEE4typeE': 
c:\Program Files (x86)\boost\boost_1_49\boost\thread\detail\thread.hpp:205: error: undefined reference to `_imp___ZN5boost6thread12start_threadEv' 
collect2.exe:-1: error: error: ld returned 1 exit status 

請告訴我這個問題? 我錯過了什麼?

M.

+0

可能重複[什麼是未定義參考/解析的外部符號錯誤,以及如何解決呢?(http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference -unresolved-external-symbol-error-and-how-do-i-fix) – sashoalm

回答

2

你沒有鏈接到Boost線程庫,你只是告訴Qt它在哪裏。的

LIBS += -L"C:/Program Files (x86)/boost/boost_1_49/lib" -lboost_thread 
+0

嗨!我已經嘗試過了。我得到「:-1:錯誤:無法找到-lboost_thread」M. – spiralfuzet

+0

即使這不起作用它是要走的路。你至少需要這個。 – UmNyobe

+0

@spiralfuzet請告訴我你沒有複製並粘貼我的示例,甚至沒有檢查在'boost_1_49/lib'目錄中調用了什麼文件!? – cmannett85

相關問題