【问题标题】:How to link external DLLs properly in Qt creator如何在 Qt creator 中正确链接外部 DLL
【发布时间】:2019-08-26 00:55:22
【问题描述】:

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

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

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 
}

然而,当我尝试构建项目时,我得到了这些错误......我不确定做错了什么或丢失了

【问题讨论】:

    标签: c++ qt dll qt5 qmake


    【解决方案1】:

    根据qmake documentation,使用 unix 标准指定链接库也可以在 Windows 上运行。无论如何,而不是

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

    我会试试的

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

    或者只使用 Windows 样式:

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

    【讨论】:

    • 我使用了这种格式 LIBS += $$PWD/dll/jpeg62.dll,它似乎可以工作,谢谢
    【解决方案2】:

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

    #include <QLibrary>
    

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

    build-test-Desktop_Qt_6_1_2_MinGW_64_bit-调试/调试

    现在很简单:

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

    或者,您可以将 dll 的位置设置为,而不是将 DLL 放在调试文件夹中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      相关资源
      最近更新 更多