“使用其他不相关的库时,找不到-lQt5Core -lQt5Gui等”

时间:2014-04-20 13:15:38

标签: c++ qt boost qt5 qmake

问题已解决(向下滚动)

我在Windows 7上并与MinGW合作。

我在QtCreator 3.01(Qt 5.2.1)中创建了一个新的Qt应用程序。我编译它,空的应用程序窗口弹出一切都很棒。但是一旦我使用任何其他库(如boost或gtest),我就会在编译时开始出现这些错误

cannot find -lqtmain
cannot find -lQt5Widgets
cannot find -lQt5Gui
cannot find -lQt5Core

ld返回1退出状态

这是我的.pro文件

#-------------------------------------------------
#
# Project created by QtCreator 2014-04-19T14:17:24
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Thermovision
TEMPLATE = app

include(Model/Model.pri)
include(Controller/Controller.pri)
include(View/View.pri)
include(Interface/Interface.pri)


SOURCES += \
    main.cpp

HEADERS  += \
    logdebug.h

FORMS    +=

OTHER_FILES += \
    Model/Model.pri \
    View/View.pri \
    Controller/Controller.pri \
    Interface/Interface.pri \
    Globals/zGlobals.pri

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

INCLUDEPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include
DEPENDPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54d

这是main.cpp

#include <iostream>
#include <QApplication>
#include "View/form.h"
#include <boost/thread.hpp>
using namespace std;


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

    boost::thread b;

    return a.exec();
}

当我评论boost线程的使用时,负责查找boost线程库的.pro文件中的include和part会再次编译。我试图使用gtest时也一样。

奇怪的是,我没有在互联网上的任何地方找到有关此问题的任何信息:&lt;

有人可以帮助我吗?

=============================================== ================================== [解决了] 好吧所以似乎qt要我明确地将库添加到项目中。我使用了生成以下输出的内置工具

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib

但我确定可以减少它(我会留下来)

1 个答案:

答案 0 :(得分:1)

根据我们的评论和结果,似乎快速解决方案是明确添加您希望使用的库。它会在后台生成这样的东西,所以基本上使用静态库而不是动态:

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib

或者,我个人建议更多的是现在在你的项目文件中添加以下行来使用动态库而不是静态来使你的应用程序二进制文件到达山上:

LIBS += -L$$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/