代码之家  ›  专栏  ›  技术社区  ›  spiralfuzet

Qt中对boost::线程的未定义引用

  •  0
  • spiralfuzet  · 技术社区  · 12 年前

    我正在尝试创建 boost::thread 在Qt中的应用。 这是我的代码:

    #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

    1 回复  |  直到 9 年前
        1
  •  2
  •   cmannett85    12 年前

    你没有链接到Boost线程库,你只是告诉Qt它在哪里。

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