简体   繁体   English

试图链接到外部静态库。 但是QT creator正在编译外部库源文件

[英]Trying to link to an external static library. But QT creator is compiling the external library source files

This is all happening on Ubuntu 18.04, with QT creator 4.5.2.这一切都发生在 Ubuntu 18.04 上,QT Creator 4.5.2。 The project is a QT widget project.该项目是一个 QT 小部件项目。 I want to link to a statically linked C++ library created in netbeans.我想链接到在 netbeans 中创建的静态链接的 C++ 库。 But when I build, QT Creator doesn't just link to the static library, it compiles a file in the library (game.cpp) and generates the following error.但是当我构建时,QT Creator 并不仅仅链接到静态库,它还会编译库(game.cpp)中的一个文件并生成以下错误。

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

I don't understand this at all.我完全不明白这一点。 Game.o is part of the external statically linked library. Game.o 是外部静态链接库的一部分。 It compiles just fine under netbeans.它在 netbeans 下编译得很好。 Is it because the library is libscrabblelib.a?是不是因为库是 libscrabblelib.a? Is that a library type that QT doesn't understand?这是 QT 不理解的库类型吗?

Here's a copy of the .pro file for my project.这是我的项目的 .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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM