简体   繁体   中英

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. The project is a QT widget project. I want to link to a statically linked C++ library created in netbeans. 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.

/home/bobp040653/Scrabble/Programming/ScrabbleLib/Game.cpp:9: error: undefined reference to `ScrabbleLib::Game::TileBag::tileValues'

I don't understand this at all. Game.o is part of the external statically linked library. It compiles just fine under netbeans. Is it because the library is libscrabblelib.a? Is that a library type that QT doesn't understand?

Here's a copy of the .pro file for my project.

#-------------------------------------------------
#
# 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 编译文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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