未定义对带有Qt的boost :: system :: generic_category()的引用 [英] Undefined reference to boost::system::generic_category() with Qt

查看:365
本文介绍了未定义对带有Qt的boost :: system :: generic_category()的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前尝试在Qt应用程序中使用Boost线程(我知道Qt有其自己的线程函数,但在这里我使用Boost),但是无论我做什么,都会出现链接器错误.网上有很多关于这个问题的问题,但到目前为止,我还无法解决.我确实知道我的boost东西工作正常,因为我可以在code :: blocks应用程序中使用所有标头,但是我只是链接到boost/stage/libs文件夹中的每个文件.

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.

出问题的最简单例子就是在文件中包含boost/thread.hpp标头

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();
}

这给了我以下错误.

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

这是我的.pro文件,显示了我如何链接到Boost库.

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

但是我的stage/libs/文件夹包含上述版本的大量不同版本,因此我不确定要链接的是哪个版本.随附的图片仅显示了我拥有的boost_system文件.应该链接哪些?

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?

谢谢.

推荐答案

您似乎在这里输入了错字:

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

这篇关于未定义对带有Qt的boost :: system :: generic_category()的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆