Search code examples
windowsqtdllqmake

Building Shared library including Qt libs via QMake on Windows


I would like to create a Dll on Windows using QMake+mingw, which includes some custom widgets and the dependent Qt libraries (linked into one library). Can this be achieved via QMake?

What I have tried so far:

Creating shared library project, and adding LIBS to .pro file:

QT       += widgets
TARGET = testqtdll
TEMPLATE = lib
DEFINES += TESTQTDLL_LIBRARY
SOURCES += testqtdll.cpp widget.cpp
HEADERS += testqtdll.h testqtdll_global.h widget.h
FORMS += widget.ui
LIBS += -lqt5core -lqt5gui -lqt5widgets

This way the resulting dll does not include QT libs.

Creating static library project, and link qt static libs. Then create dll after:

QT       += widgets    
TARGET = testqtlib
TEMPLATE = lib
CONFIG += staticlib    
SOURCES += testqtlib.cpp widget.cpp
HEADERS += testqtlib.h widget.h
FORMS += widget.ui
LIBS += c:/Qt/Static/5.3.1/lib/Qt5Core.a
LIBS += c:/Qt/Static/5.3.1/lib/Qt5Gui.a 
LIBS += c:/Qt/Static/5.3.1/lib/Qt5Widgets.a

This way the resulting lib also does not include QT libs.


Solution

  • I found a solution after all. One should use the Qt static build to create such dll. Working project file:

    QT       += core gui widgets
    CONFIG += static dll
    TARGET = testqtdll
    TEMPLATE = lib
    DEFINES += TESTQTDLL_LIBRARY
    SOURCES += testqtdll.cpp widget.cpp
    HEADERS += testqtdll.h testqtdll_global.h widget.h
    FORMS += widget.ui