Bug 1529178 - Can't link mingw64 Qt5 widgets application statically
Summary: Can't link mingw64 Qt5 widgets application statically
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: mingw-qt5-qtbase
Version: 27
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Sandro Mani
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-12-26 22:30 UTC by Alexis Jeandet
Modified: 2018-11-30 21:59 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1257630
Environment:
Last Closed: 2018-11-30 21:59:34 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Alexis Jeandet 2017-12-26 22:30:37 UTC
+++ This bug was initially created as a clone of Bug #1257630 +++

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.

--- Additional comment from Erik van Pienbroek on 2015-08-28 08:01:21 EDT ---

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

--- Additional comment from andreas.mack on 2015-08-28 09:03:27 EDT ---

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

--- Additional comment from Erik van Pienbroek on 2015-08-28 11:48:09 EDT ---

Okay, that's a completely separate issue in the mingw-angleproject package but I'll look into it

--- Additional comment from andreas.mack on 2015-08-28 12:08:25 EDT ---

Thanks. I can open another bug if you want.

--- Additional comment from Erik van Pienbroek on 2015-08-28 12:26:22 EDT ---

This bug report is sufficient for now

--- Additional comment from andreas.mack on 2015-09-16 07:27:20 EDT ---

Anything I can help with here? I'd love to built the application statically.

--- Additional comment from Taylor Braun-Jones on 2015-11-06 22:50:58 EST ---

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!

--- Additional comment from Taylor Braun-Jones on 2015-11-10 21:10:44 EST ---

@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.

--- Additional comment from Fedora Update System on 2015-12-30 19:12:39 EST ---

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

--- Additional comment from Fedora Update System on 2016-01-02 22:24:08 EST ---

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

--- Additional comment from Fedora Update System on 2016-01-12 03:02:00 EST ---

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.

--- Additional comment from andreas.mack on 2016-01-15 02:44:22 EST ---

Better late than never: I confirm it works now as expected, bug is fixed.

--- Additional comment from Taylor Braun-Jones on 2016-01-19 09:31:29 EST ---

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}

--- Additional comment from andreas.mack on 2016-01-19 10:39:43 EST ---

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

--- Additional comment from Taylor Braun-Jones on 2016-01-20 14:57:29 EST ---

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.

Comment 1 Sandro Mani 2017-12-26 22:54:56 UTC
Uhm, so what's actually the bug report?

Comment 2 Alexis Jeandet 2017-12-26 23:02:53 UTC
In fact, it seems that it doesn't works with latest mingw-qt5-qtbase (5.9.3-2.fc27). I tried most of the solutions proposed on previous bug report.

I tried a simple project with an empty main windows, I didn't succeed to statically link. 

When I add LIBS += -lqwindows, I get:
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libqwindows.a(qwindowsbackingstore.o):(.text+0xcf): undefined reference to `QWindowsNativeImage::~QWindowsNativeImage()'

When I add LIBS += -lQt5PlatformSupport it doesn't find Qt5PlatformSupport.

Comment 3 Sandro Mani 2017-12-26 23:09:43 UTC
Looks indeed like libQt5PlatformSupport.a is missing, but I see it in mingw-qt5-qtbase-5.10.0.fc28. Not immediately clear why it is missing in 5.9.3.

Comment 4 Pierre Blavy 2018-06-13 07:57:08 UTC
WORKAROUND : 

The libQt5PlatformSupport.a is a particular non portable way, among others, to distribute the static QtCode. On F28, this file is missing because the code is elsewhere. On my particular computer the workaround was to add to my .pro

LIBS += -lQt5FontDatabaseSupport -lQt5EventDispatcherSupport -ldwmapi -lQt5VulkanSupport -lQt5ThemeSupport -lQt5AccessibilitySupport



Method :

In the general case, we do have to search for the missing code in a set of lib. For every missing dependency XXXX run something like:

nm -l --demangle --print-file-name /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5*.a | grep  XXXX


Then, look at symbols that are not undefined (not marked as U), to get the lib that contains the missing stuff.

Comment 5 Ben Cotton 2018-11-27 15:10:47 UTC
This message is a reminder that Fedora 27 is nearing its end of life.
On 2018-Nov-30  Fedora will stop maintaining and issuing updates for
Fedora 27. It is Fedora's policy to close all bug reports from releases
that are no longer maintained. At that time this bug will be closed as
EOL if it remains open with a Fedora  'version' of '27'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 27 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 6 Ben Cotton 2018-11-30 21:59:34 UTC
Fedora 27 changed to end-of-life (EOL) status on 2018-11-30. Fedora 27 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


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