【问题标题】:Trying to link to an external static library. But QT creator is compiling the external library source files试图链接到外部静态库。但是 QT creator 正在编译外部库源文件
【发布时间】:2020-03-06 17:14:40
【问题描述】:

这一切都发生在 Ubuntu 18.04 和 QT creator 4.5.2 上。该项目是一个 QT 小部件项目。我想链接到在 netbeans 中创建的静态链接 C++ 库。但是当我建造时, QT Creator 不只是链接到静态库,它会编译库中的一个文件(game.cpp)并生成以下错误。

/home/bobp040653/Scrabble/Programming/ScrabbleLib/Game.cpp:9:错误:未定义对 `ScrabbleLib::Game::TileBag::tileValues' 的引用

我完全不明白。 Game.o 是外部静态链接库的一部分。 它在netbeans下编译得很好。是因为库是 libscrabblelib.a 吗? 那是 QT 不理解的库类型吗?

这是我项目的 .pro 文件的副本。

#-------------------------------------------------
#
# Project created by QtCreator 2020-03-03T10:32:12
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = TipTopQTW
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        tiptop.cpp

HEADERS += \
        tiptop.h

FORMS += \
        tiptop.ui

unix:!macx: LIBS += -L$$PWD/../ScrabbleLib/dist/Debug/GNU-Linux/ -lscrabblelib

INCLUDEPATH += $$PWD/../ScrabbleLib
DEPENDPATH += $$PWD/../ScrabbleLib

unix:!macx: PRE_TARGETDEPS += $$PWD/../ScrabbleLib/dist/Debug/GNU-Linux/libscrabblelib.a

【问题讨论】:

    标签: c++ qt-creator static-libraries


    【解决方案1】:

    您添加了DEPENDPATH += $$PWD/../ScrabbleLib,它告诉 Qt 编译文件。

    【讨论】:

    • 我将 DEPENDPATH 注释掉了,但构建系统仍然构建 Game.cpp。我确实注意到它构建了 Game.o 和 Game.d。我在想 Game.d 是一个依赖文件。有谁知道 Game.d 是什么?当 netbeans 构建库时,它不会创建 .d 文件。我很想知道这里发生了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    相关资源
    最近更新 更多