如何在 Qt Creator 中正确 link 外部 DLL

How to link external DLLs properly in Qt creator

我正在尝试构建找到的项目 @ uconfig , 该项目需要 poppler 并且作者提供了预建链接 headers and DLLS

我已经下载了,这是项目的结构

dll 文件夹包含所有 DLLS,poppler 包含头文件, pdf_extract.pro 具有以下内容

QT     += core gui widgets xml

TARGET = pdf_extract
TEMPLATE = lib
DEFINES += DATASHEET_EXTRACTOR_EXPORT_LIB
DESTDIR = "$$PWD/../../bin"

CONFIG(release, debug|release) {
    CONFIG += optimize_full
}

SOURCES += \
    $$PWD/datasheet.cpp \
    $$PWD/datasheetpackage.cpp \
    $$PWD/datasheetpin.cpp \
    $$PWD/datasheetbox.cpp \
    $$PWD/pdfdebugwidget/pdfdebugwidget.cpp \
    $$PWD/pdfdebugwidget/pdfdebugviewer.cpp \
    $$PWD/pdfdebugwidget/pdfdebugscene.cpp \
    $$PWD/pdfdebugwidget/pdfdebugitempage.cpp \
    $$PWD/pdfdebugwidget/pdfdebugitempin.cpp \
    $$PWD/pdfdebugwidget/pdfdebugitemtextbox.cpp \
    $$PWD/model/pdfdatasheet.cpp \
    $$PWD/model/pdfpage.cpp \
    $$PWD/model/pdftextbox.cpp \
    $$PWD/model/pdfpin.cpp \
    $$PWD/model/pdfcomponent.cpp \
    $$PWD/controller/pdfloader.cpp

HEADERS += \
    $$PWD/pdf_extract_common.h \
    $$PWD/datasheet.h \
    $$PWD/datasheetpackage.h \
    $$PWD/datasheetpin.h \
    $$PWD/datasheetbox.h \
    $$PWD/pdfdebugwidget/pdfdebugwidget.h \
    $$PWD/pdfdebugwidget/pdfdebugviewer.h \
    $$PWD/pdfdebugwidget/pdfdebugscene.h \
    $$PWD/pdfdebugwidget/pdfdebugitempage.h \
    $$PWD/pdfdebugwidget/pdfdebugitempin.h \
    $$PWD/pdfdebugwidget/pdfdebugitemtextbox.h \
    $$PWD/model/pdfdatasheet.h \
    $$PWD/model/pdfpage.h \
    $$PWD/model/pdftextbox.h \
    $$PWD/model/pdfpin.h \
    $$PWD/model/pdfcomponent.h \
    $$PWD/controller/pdfloader.h

LIBS += -L"$$PWD/../../bin"
LIBS += -L"$$PWD/dll/jpeg62.dll"
LIBS += -L"$$PWD/dll/libfreetype-6.dll"
LIBS += -L"$$PWD/dll/libopenjp2.dll"
LIBS += -L"$$PWD/dll/libpng12.dll"
LIBS += -L"$$PWD/dll/libpoppler-80.dll"
LIBS += -L"$$PWD/dll/libpoppler-qt5.dll"
LIBS += -L"$$PWD/dll/libtiff3.dll"
LIBS += -L"$$PWD/dll/zlib1.dll"

INCLUDEPATH += $$PWD/../../


LIBS += -lkicad

macx {
    LIBS += -L /usr/local/lib
    INCLUDEPATH += /usr/local/include 
}

然而,当我尝试构建项目时,出现了这些错误...我不确定做错了什么或遗漏了什么

根据 qmake documentation,使用 unix 标准指定链接库也适用于 Windows。无论如何,而不是

LIBS += -L"$$PWD/dll/jpeg62.dll"

我会试试

LIBS += "-L$$PWD/dll" - ljpeg62

或者只使用 Windows 样式:

LIBS += $$PWD/dll/jpeg62.dll

晚了 2 年,但我也一直在想,

#include <QLibrary>

将您的 *.dll 放入您的 Debug/Release 文件夹中。例如:

build-test-Desktop_Qt_6_1_2_MinGW_64_bit-Debug/debug

现在只需:

QLibrary lib("myLibrary.dll");

if (!lib.load())
    qDebug() << lib.errorString();
if (lib.load())
    qDebug() << "library loaded";

或者,您可以将 dll 的位置设置为

,而不是将 DLL 放在调试文件夹中

c:/path/to/dll/yourdll.dll