Bug 1257630 - Can't link mingw32 Qt5 widgets application statically
Summary: Can't link mingw32 Qt5 widgets application statically
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: mingw-qt5-qtbase
Version: 23
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Erik van Pienbroek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-08-27 13:44 UTC by Andreas Mack
Modified: 2016-01-20 19:57 UTC (History)
3 users (show)

Fixed In Version: mingw-qt5-qtbase-5.5.1-2.fc23
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1529178 (view as bug list)
Environment:
Last Closed: 2016-01-12 08:02:06 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Andreas Mack 2015-08-27 13:44:54 UTC
Description of problem:
I can't link at Qt5 Widgets application statically. I get the dreaded "qwindows.dll missing" error.
CONFIG+=static
If I add 
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
in my main, I get a compile error:
release/main.o: In function `ZN45StaticQWindowsIntegrationPluginPluginInstanceC4Ev':
/git/ecenctool/main.cpp:10: undefined reference to `qt_static_plugin_QWindowsIntegrationPlugin()'
This does not help:
win32-g++: LIBS += -lQt5PlatformSupport
I'm using
/usr/i686-w64-mingw32/bin/qt5/qmake

Version-Release number of selected component (if applicable):
mingw32-qt5-qtbase-static-5.4.1-2.fc22.noarch

How reproducible:
Link a Qt5 Widgets app statically, execute it on windows.


Steps to Reproduce:
1. Use a Qt5 example
2. add CONFIG+=static, add Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) to main
3. qmake && make, copy to windows, double click

Actual results:
qwindows.dll is missing

Expected results:
Application executes.

Additional info:
I think libqwindows.a is missing from the -static rpm.

Comment 1 Erik van Pienbroek 2015-08-28 12:01:21 UTC
I've prepared a test build @ http://koji.fedoraproject.org/koji/taskinfo?taskID=10861088
Could you please try to install this test build. Adding LIBS += -lqwindows to your .pro file should be enough to get the qwindows plugin linked in statically

Comment 2 Andreas Mack 2015-08-28 13:03:27 UTC
Looks better, but now DllMain pops up. Can you fix this one?


x86_64-w64-mingw32-g++ -g -static -static-libgcc -static-libstdc++ -static -Wl,-subsystem,windows -mthreads -o release/ECEncTool.exe release/main.o release/ecmainwindow.o release/ecencrypt.o release/moc_ecmainwindow.o release/moc_ecencrypt.o  -lmingw32 -lqt5main -lQt5PlatformSupport -lqwindows -L/home/vasquez/git/libsodium-win64/lib -lsodium -lQt5Widgets -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -ljpeg -lpng -lharfbuzz -lglib-2.0 -lintl -lwinmm -lQt5Xml -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -lkernel32 -lz -lpcre16 -lEGL -lGLESv2 -ld3d9 -ldxguid -lgdi32 -luser32 
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libGLESv2.a(main.o):(.text+0x131): multiple definition of `DllMain'
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libEGL.a(main.o):(.text+0x117): first defined here
collect2: error: ld returned 1 exit status

Comment 3 Erik van Pienbroek 2015-08-28 15:48:09 UTC
Okay, that's a completely separate issue in the mingw-angleproject package but I'll look into it

Comment 4 Andreas Mack 2015-08-28 16:08:25 UTC
Thanks. I can open another bug if you want.

Comment 5 Erik van Pienbroek 2015-08-28 16:26:22 UTC
This bug report is sufficient for now

Comment 6 Andreas Mack 2015-09-16 11:27:20 UTC
Anything I can help with here? I'd love to built the application statically.

Comment 7 Taylor Braun-Jones 2015-11-07 03:50:58 UTC
I was also hit by this bug. I'm running the Fedora 23 docker image. Is there a test build for Fedora 23 that I can try out? I'll report back with my findings. Thanks for all the great mingw packaging!

Comment 8 Taylor Braun-Jones 2015-11-11 02:10:44 UTC
@Erik, Do you still have the .spec with the proposed fix? If so I can build an RPM and test out the fix for my use case. Or if you just let me know generally what the fix was, I'll try to recreate it myself.

Comment 9 Fedora Update System 2015-12-31 00:12:39 UTC
mingw-qt5-qtxmlpatterns-5.5.1-1.fc23 mingw-qt5-qtwinextras-5.5.1-1.fc23 mingw-qt5-qtwebsockets-5.5.1-1.fc23 mingw-qt5-qtwebkit-5.5.1-1.fc23 mingw-qt5-qttranslations-5.5.1-1.fc23 mingw-qt5-qttools-5.5.1-1.fc23 mingw-qt5-qtsvg-5.5.1-1.fc23 mingw-qt5-qtsensors-5.5.1-1.fc23 mingw-qt5-qtscript-5.5.1-1.fc23 mingw-qt5-qtquick1-5.5.1-1.fc23 mingw-qt5-qtmultimedia-5.5.1-1.fc23 mingw-qt5-qtlocation-5.5.1-1.fc23 mingw-qt5-qtimageformats-5.5.1-1.fc23 mingw-qt5-qtgraphicaleffects-5.5.1-1.fc23 mingw-qt5-qtdeclarative-5.5.1-1.fc23 mingw-qt5-qtbase-5.5.1-1.fc23 mingw-qt5-qtactiveqt-5.5.1-1.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2015-bc03865b2e

Comment 10 Fedora Update System 2016-01-03 03:24:08 UTC
mingw-angleproject-0-0.13.git.30d6c2.20141113.fc23, mingw-qt5-qtactiveqt-5.5.1-1.fc23, mingw-qt5-qtbase-5.5.1-2.fc23, mingw-qt5-qtdeclarative-5.5.1-1.fc23, mingw-qt5-qtgraphicaleffects-5.5.1-1.fc23, mingw-qt5-qtimageformats-5.5.1-1.fc23, mingw-qt5-qtlocation-5.5.1-1.fc23, mingw-qt5-qtmultimedia-5.5.1-1.fc23, mingw-qt5-qtquick1-5.5.1-1.fc23, mingw-qt5-qtscript-5.5.1-1.fc23, mingw-qt5-qtsensors-5.5.1-1.fc23, mingw-qt5-qtsvg-5.5.1-1.fc23, mingw-qt5-qttools-5.5.1-1.fc23, mingw-qt5-qttranslations-5.5.1-1.fc23, mingw-qt5-qtwebkit-5.5.1-1.fc23, mingw-qt5-qtwebsockets-5.5.1-1.fc23, mingw-qt5-qtwinextras-5.5.1-1.fc23, mingw-qt5-qtxmlpatterns-5.5.1-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-bc03865b2e

Comment 11 Fedora Update System 2016-01-12 08:02:00 UTC
mingw-angleproject-0-0.13.git.30d6c2.20141113.fc23, mingw-qt5-qtactiveqt-5.5.1-1.fc23, mingw-qt5-qtbase-5.5.1-2.fc23, mingw-qt5-qtdeclarative-5.5.1-1.fc23, mingw-qt5-qtgraphicaleffects-5.5.1-1.fc23, mingw-qt5-qtimageformats-5.5.1-1.fc23, mingw-qt5-qtlocation-5.5.1-1.fc23, mingw-qt5-qtmultimedia-5.5.1-1.fc23, mingw-qt5-qtquick1-5.5.1-1.fc23, mingw-qt5-qtscript-5.5.1-1.fc23, mingw-qt5-qtsensors-5.5.1-1.fc23, mingw-qt5-qtsvg-5.5.1-1.fc23, mingw-qt5-qttools-5.5.1-1.fc23, mingw-qt5-qttranslations-5.5.1-1.fc23, mingw-qt5-qtwebkit-5.5.1-1.fc23, mingw-qt5-qtwebsockets-5.5.1-1.fc23, mingw-qt5-qtwinextras-5.5.1-1.fc23, mingw-qt5-qtxmlpatterns-5.5.1-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 12 Andreas Mack 2016-01-15 07:44:22 UTC
Better late than never: I confirm it works now as expected, bug is fixed.

Comment 13 Taylor Braun-Jones 2016-01-19 14:31:29 UTC
I'm still getting the same "could not find or load the Qt platform plugin 'windows'" error.

@andreas.mac - Do you maybe have a minimal example that you could share that you've had success with?

This is the Dockerfile I used to create a container for the build:

FROM fedora:23
RUN dnf install -y \
  ccache \
  make \
  mingw32-gcc-c++ \
  mingw32-qt5-qtbase-static \
  mingw32-winpthreads-static \
  upx \
  && dnf clean all
ENV PATH=/usr/lib64/ccache:/usr/i686-w64-mingw32/bin/qt5:${PATH}

Comment 14 Andreas Mack 2016-01-19 15:39:43 UTC
I think the important stuff is in the pro file. I use this:

TEMPLATE = app
CONFIG += static
DEFINE += static


...
win32-g++: LIBS += -lQt5PlatformSupport -lqwindows
#win32-g++: QTPLUGIN += Qt5WindowsIntegration
win32-g++: QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++
win32-g++: QMAKE_CFLAGS += -DQT_STATICPLUGIN
...
In the main.c:
....
#include <QtPlugin>
  Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
....

I have pretty much everything from mingw64-*-static-* installed also.

HTH

Comment 15 Taylor Braun-Jones 2016-01-20 19:57:29 UTC
Thanks! Now I too can confirm that the new mingw32-qt5-*-static packages are able to build applications with the qwindows plugin statically linked.

For the record, I only needed this in my .pro file:

--- snip ---
CONFIG += static
# The documented method of using "QTPLUGIN += qwindows" is broken. The
# workaround is to use:
LIBS += -lqwindows
--- snip ---

And this in my main.cpp:

--- snip ---
#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
--- snip ---

Everything else was not necessary for me.


Note You need to log in before you can comment on or make changes to this bug.