2

Currently trying to use boost threads in a Qt application (I know Qt has its own thread functions but here I'm using boost) but I get linker errors no matter what I do. There's a ton of questions around the net about this problem but so far I have not been able to solve it. I do know my boost stuff works right because I can use all the headers in a code::blocks application but in that I just linked to every single file in the boost/stage/libs folder.

The simplest example where things go wrong is just including the boost/thread.hpp header in a file

#include "MainWindow.h"
#include <QApplication>

#include <boost/thread.hpp>

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

And this gives me the following error.

C:\boost_1_53_0\boost\system\error_code.hpp:214: error: undefined reference to                `boost::system::generic_category()'

Here's my .pro file showing how I linked to the boost libraries.

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = BoostTest
TEMPLATE = app

INCLUDEPATH += C:/boost_1_53_0/
LIB += -LC:/boost_1_53_0/stage/lib/ \
    -lboost_system-mgw47-1_53 \
    -lboost_filesystem-mgw47-mt-1_53 \
    -lboost_thread-mgw47-mt-1_53

SOURCES += main.cpp\
           MainWindow.cpp

HEADERS  += MainWindow.h

FORMS    += MainWindow.ui

I've tried all permutations of ordering on the libraries so I know it's not the order in which they are linked that is the problem. I'm wondering if, first of all, the syntax of the above linking is correct and secondly. if I'm actually including the correct files. I also tried linking with

-lboost_system \
-lboost_filesystem \
-lboost_thread

But my stage/libs/ folder contains a ton of different versions of the above so I wasn't sure which ones were being linked. Attached is a pic showing just the boost_system files I have. Which ones should be linked?

enter image description here

Thanks.

4

1 回答 1

2

You seem to have made a typo here:

LIB += -LC:/boost_1_53_0/stage/lib/ \

This should be (note the plural at the end of the variable):

LIBS += -LC:/boost_1_53_0/stage/lib/ \

... and yes, you should use this formula as opposed to the long version you initially wrote:

-lboost_system \
-lboost_filesystem \
-lboost_thread
于 2013-10-06T00:08:58.640 回答