Qt static build missing windows plugin - c++

I've compiled Qt 5.9.3 to static library using
configure -static -release -platform win32-msvc
I'm compiling my application and it compiles and links successfully but when I start it it fails with
This application failed to start because it could not find or load the Qt platform plugin "windows"
The problem is clearly that it fails to find the qwindows plugin which is now a .lib and not a .dll
I tried adding qwindows.lib to the linker input files but that did not have any effect.
Is there a known fix for this issue?

May be you linked another Qt lib. If so, your application will require windows plugin.
Use tools like dependcy walker http://dependencywalker.com/ find out what dll your application depends on.
Tips: I used to installed anaconda, and build qt from source, my application linked qt lib of anaconda, so it require windows plugin and never find the dll.

Related

Build static linked app with Qt5 on Windows [duplicate]

I am trying to deploy(release to public) a simple qt application I made recently, but got stuck at static linking qt libs.
I followed the guide on qt docs to re-build qt and my app statically. But the release build still require qtgui / qtcore dll for no apparent reasons, I wonder if anyone has seen this kind of problems before ? Or even better, has successfully resolved it ?
http://doc.qtsoftware.com/4.5/deployment-windows.html
I wrote a guide to static linking
and
How to build Qt static with multiple compilers and keep it small
(because it can get pretty big, especially for simple programs).
You may also want to check out the BitRock installer, which is free for open source projects.
In short, it turns out to be a little more complex if you are using anything Qt thinks of as a plugin, such as support for most image types (JPEG, GIF) or databases.
For example, if you want to include support for Oracle DBMS and GIF images for your icons, you add the following to your .PRO file:
QTPLUGIN += qsqloci qgif
CONFIG += static
You will then need to:
#include <QtPlugin>
in your project, and import any plugins used. You need to change these settings back order to get it to compile with dynamic linking again (like when debugging or adding features), though this can be easily automated. There are also considerations when building the Qt libraries for use with static linking, though the Qt instructions will at least get you started.
With Qt 5.5, things are quite easy. There's the configure script you have to run before building Qt. There are following orthogonal settings that you pass to configure:
Do you want a static Qt library?
-static option should be passed to configure
Do you want the build of Qt, and of your application, to use a static C++ runtime?
-static-runtime option should be passed to configure
Do you want XP targeting?
-target xp option should be passed to configure
Additionally, follow the instructions from this blog post.
Qt Creator didn't support XP targeting automagically at least until v.3.5.0 since it doesn't set up the environment for the build tools properly. You have to modify the build environment manually per the blog post.
Also, be aware that your static build will still link to the visual studio runtimes dynamically!
See this faq (internet archive link, in case the link goes away) :
Why does a statically built Qt use the dynamic Visual Studio runtime libraries ? Do I need to deploy those with my application ?
Qt is built using the -MD(d) switch, which links against the dynamic C/C++ runtime libraries. This is necessary as we have experienced memory problems when using anything but the -MD(d) flag, and in general, it is recommended to use. You should not alter this flag yourself for your application, because it conflicts with how the Qt library is built if you change the flag to -MT. You should not change it for Qt either, since it is likely to cause problems.
Qt is still built statically when using the -static option though, meaning you do not need to distribute the Qt dlls when deploying your application. You will have to distribute the C runtimes though (if they don't already exist on the target machine), see our deployment documentation http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies.
msys2 has a pre-built static Qt5 package
e.g. pacman -S mingw-w64-qt5-static
Currently, to also get all dependencies of Qt statically linked, with CMake, you need to add:
list(PREPEND CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
before calling find_package(Qt5…
CMAKE_AUTOSTATICPLUGINS was replaced by a new upstream implementation and is not needed anymore.
I just compiled an application statically (Debug)
with QT Plugins(5.9),
with VS (2015) (Win).
a) Add to your code.
#include <QtPlugin>
Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);
b) Add the following to the link paths
\5.9.0_x86_static_install\lib
\5.9.0_x86_static_install\bin
\5.9.0_x86_static_install\plugins
\5.9.0_x86_static_install\plugins\platforms
\5.9.0_x86_static_install\plugins\imageformats
c) Add the list of QT static libraries and internal VS libraries to your link list.
version.lib
imm32.lib
shlwapi.lib
rpcrt4.lib
Ws2_32.lib
Mpr.lib
Netapi32.lib
Rpcrt4.lib
Iphlpapi.lib
winmm.lib
gdi32.lib
advapi32.lib
msimg32.lib
UxTheme.lib
translatord.lib
preprocessord.lib
d3d9.lib
dxguid.lib
libEGLd.lib
libGLESv2d.lib
iphlpapi.lib
psapi.lib
ws2_32.lib
Dwmapi.lib
Qt5CoreD.lib
Qt5Guid.lib
Qt5Xmld.lib
Qt5Widgetsd.lib
Qt5Networkd.lib
Qt5Winextrasd.lib
Qt5PlatformCompositorSupportd.lib
qicod.lib
qtmaind.lib
qtlibpngd.lib
qtharfbuzzd.lib
qtpcre2d.lib
qwindowsd.lib
Qt5FontDatabaseSupportd.lib
Qt5ThemeSupportd.lib
Qt5EventDispatcherSupportd.lib
Qt5AccessibilitySupportd.lib
qtfreetyped.lib
Kevin Higgins
I recommend you to use linuxdeployqt this tool. It can help solve most of the dependency problems. And I use it to package my qt application successfully.
This answer applies to using MSYS2 with mingw-w64 as the compiler, in Windows, and qmake. The QT version is 5.15.0.
Installing the package qt5-static gives you a build of QT that produces executables who don't rely on any QT DLLs. (Example commandline - pacman -Ss mingw64/mingw-w64-x86_64-qt5-static).
However a new problem is introduced here: it does not pass the -static flag to gcc. Meaning that although the executable does not depend on QT DLLs, it does depend on libgcc-s, libwinpthread.dll etc.
Normally, this problem would be fixed by using CONFIG += static which causes qmake to pass -static to gcc. However, and as noted in the other answers, for a qt-static build that config option is ignored!
To solve this I had to manually specify the gcc flags for static linking in the qmake file, i.e. :
QMAKE_CXXFLAGS += -static
QMAKE_LFLAGS_WINDOWS += -static
Which results in a (large) binary with no external dependencies other than Windows system DLLs.
(In case it matters: my use case was building a COM in-process server DLL that should have no external dependencies; I was also using TEMPLATE=lib and CONFIG += dll).

QT missing dll after deploy

I've copied all of the dlls from QT that were required, and my application works fine on my Windows server machine.
However when trying to run it on a Windows 7 box i get the following message:
This application failed to start because it could not find or load he
Qt platform plugin "windows".
Reinstallning the application may fix this problem.
Any ideas what I'm missing here?
I'd scratched my head over this some time ago. It turned out that this was caused not by missing qwindows.dll, but rather one of libEGL.dll or libGLESv2.dll. This was tricky, because dependency walker does not show those libs as direct dependencies.
If you want to test on your dev machine, whether your app has all required libs, fire up console issue SET PATH=, cd to your app directory and run it.
This is complete list of dlls that my app is using (Qt 5.2 / QtQuick app only, rest is C++). QtQuick is nice but the size of Qt dependencies is a bit scary:
icu*.dll - depending on whether you've compiled with ICU
libEGL.dll
libGLESv2.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Widgets.dll
Widely used solution is put all necessary libraris in the folder of application.
What are libraries application need?
Run application and see error message:
The program can't start because <Library name> is missing from your computer.
Try reinstalling the program to fix this problem
Library set is depended from Qt version. Run several times application and each time copy required lib you found what is neeeded for application.
In my case (Qt 5.2.1) there are
icudt51.dll,
icuin51.dll,
icuuc51.dll,
libgcc_s_dw2-1.dll,
libstdc++-6.dll,
libwinpthread-1.dll,
Qt5Core.dll,
Qt5Gui.dll,
Qt5Widgets.dll.
All libs you can found in your Qt install folder. But don't use libraries from Tools\QtCreator folder, because QtCreator has another version of these libraries!
In case of error:
This application failed to start because it could not find or load he Qt platform plugin windows. Reinstallning the application may fix this problem.
You should create folder platforms and copy qwindows.dll into it.
If you still got error you should create qt.conf file in application's folder with content:
[Paths]
Plugins=plugins
This solution is described in https://qt-project.org/forums/viewthread/37265
More information about qt.conf you can find at http://qt-project.org/doc/qt-5/qt-conf.html
In latest versions of Qt you can find deploy tool (since 5.2). This tool find necessary libraries for application and copy into application folder. You can run it something like this:
call c:\Qt\QtX.Y.Z\X.Y.Z\mingw48_32\bin\qtenv2.bat
cd /d "c:\path\to\your\application\folder"
windeployqt.exe your_application.exe
Generally it works well. But I notice that some libraries are not copied, but you can found by method is descibed at beggining of post. More useful information you can find at
http://qt-project.org/doc/qt-5/windows-deployment.html
In rare cases yo can got this error if some library is missing but not appear in error message above. Example: Qt 5.1.1: Application failed to start because platform plugin "windows" is missing
I wasn't in this situation, so I can't tell more.

Static linking in Windows [duplicate]

I am trying to deploy(release to public) a simple qt application I made recently, but got stuck at static linking qt libs.
I followed the guide on qt docs to re-build qt and my app statically. But the release build still require qtgui / qtcore dll for no apparent reasons, I wonder if anyone has seen this kind of problems before ? Or even better, has successfully resolved it ?
http://doc.qtsoftware.com/4.5/deployment-windows.html
I wrote a guide to static linking
and
How to build Qt static with multiple compilers and keep it small
(because it can get pretty big, especially for simple programs).
You may also want to check out the BitRock installer, which is free for open source projects.
In short, it turns out to be a little more complex if you are using anything Qt thinks of as a plugin, such as support for most image types (JPEG, GIF) or databases.
For example, if you want to include support for Oracle DBMS and GIF images for your icons, you add the following to your .PRO file:
QTPLUGIN += qsqloci qgif
CONFIG += static
You will then need to:
#include <QtPlugin>
in your project, and import any plugins used. You need to change these settings back order to get it to compile with dynamic linking again (like when debugging or adding features), though this can be easily automated. There are also considerations when building the Qt libraries for use with static linking, though the Qt instructions will at least get you started.
With Qt 5.5, things are quite easy. There's the configure script you have to run before building Qt. There are following orthogonal settings that you pass to configure:
Do you want a static Qt library?
-static option should be passed to configure
Do you want the build of Qt, and of your application, to use a static C++ runtime?
-static-runtime option should be passed to configure
Do you want XP targeting?
-target xp option should be passed to configure
Additionally, follow the instructions from this blog post.
Qt Creator didn't support XP targeting automagically at least until v.3.5.0 since it doesn't set up the environment for the build tools properly. You have to modify the build environment manually per the blog post.
Also, be aware that your static build will still link to the visual studio runtimes dynamically!
See this faq (internet archive link, in case the link goes away) :
Why does a statically built Qt use the dynamic Visual Studio runtime libraries ? Do I need to deploy those with my application ?
Qt is built using the -MD(d) switch, which links against the dynamic C/C++ runtime libraries. This is necessary as we have experienced memory problems when using anything but the -MD(d) flag, and in general, it is recommended to use. You should not alter this flag yourself for your application, because it conflicts with how the Qt library is built if you change the flag to -MT. You should not change it for Qt either, since it is likely to cause problems.
Qt is still built statically when using the -static option though, meaning you do not need to distribute the Qt dlls when deploying your application. You will have to distribute the C runtimes though (if they don't already exist on the target machine), see our deployment documentation http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies.
msys2 has a pre-built static Qt5 package
e.g. pacman -S mingw-w64-qt5-static
Currently, to also get all dependencies of Qt statically linked, with CMake, you need to add:
list(PREPEND CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
before calling find_package(Qt5…
CMAKE_AUTOSTATICPLUGINS was replaced by a new upstream implementation and is not needed anymore.
I just compiled an application statically (Debug)
with QT Plugins(5.9),
with VS (2015) (Win).
a) Add to your code.
#include <QtPlugin>
Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);
b) Add the following to the link paths
\5.9.0_x86_static_install\lib
\5.9.0_x86_static_install\bin
\5.9.0_x86_static_install\plugins
\5.9.0_x86_static_install\plugins\platforms
\5.9.0_x86_static_install\plugins\imageformats
c) Add the list of QT static libraries and internal VS libraries to your link list.
version.lib
imm32.lib
shlwapi.lib
rpcrt4.lib
Ws2_32.lib
Mpr.lib
Netapi32.lib
Rpcrt4.lib
Iphlpapi.lib
winmm.lib
gdi32.lib
advapi32.lib
msimg32.lib
UxTheme.lib
translatord.lib
preprocessord.lib
d3d9.lib
dxguid.lib
libEGLd.lib
libGLESv2d.lib
iphlpapi.lib
psapi.lib
ws2_32.lib
Dwmapi.lib
Qt5CoreD.lib
Qt5Guid.lib
Qt5Xmld.lib
Qt5Widgetsd.lib
Qt5Networkd.lib
Qt5Winextrasd.lib
Qt5PlatformCompositorSupportd.lib
qicod.lib
qtmaind.lib
qtlibpngd.lib
qtharfbuzzd.lib
qtpcre2d.lib
qwindowsd.lib
Qt5FontDatabaseSupportd.lib
Qt5ThemeSupportd.lib
Qt5EventDispatcherSupportd.lib
Qt5AccessibilitySupportd.lib
qtfreetyped.lib
Kevin Higgins
I recommend you to use linuxdeployqt this tool. It can help solve most of the dependency problems. And I use it to package my qt application successfully.
This answer applies to using MSYS2 with mingw-w64 as the compiler, in Windows, and qmake. The QT version is 5.15.0.
Installing the package qt5-static gives you a build of QT that produces executables who don't rely on any QT DLLs. (Example commandline - pacman -Ss mingw64/mingw-w64-x86_64-qt5-static).
However a new problem is introduced here: it does not pass the -static flag to gcc. Meaning that although the executable does not depend on QT DLLs, it does depend on libgcc-s, libwinpthread.dll etc.
Normally, this problem would be fixed by using CONFIG += static which causes qmake to pass -static to gcc. However, and as noted in the other answers, for a qt-static build that config option is ignored!
To solve this I had to manually specify the gcc flags for static linking in the qmake file, i.e. :
QMAKE_CXXFLAGS += -static
QMAKE_LFLAGS_WINDOWS += -static
Which results in a (large) binary with no external dependencies other than Windows system DLLs.
(In case it matters: my use case was building a COM in-process server DLL that should have no external dependencies; I was also using TEMPLATE=lib and CONFIG += dll).

Statically linked app with Qt gives error: Failed to load platform plugin "windows"

I have built Qt 5.0.1 statically in VS 2010 under Windows 7 x64. The configuration parameters were
configure -debug-and-release -opensource -confirm-license -platform win32-msvc2010 -nomake examples -nomake tests -no-webkit -static
and I performed the build with jom with following parameters:
jom -j 4
The build process was successful and I can find all the libs and link my app with Qt statically. Now the problem is that when I try to run the application, it gives me an error
Module: 5.0.1
File: kernel\qguiapplication.cpp
Line: 781
"Failed to load platform plugin "windows". Available platforms are:"
But below this error, it does not show up any platforms. I encountered the same error while linking with Qt dynamically. I got rid of that by placing dependency DLLs (qt5core.dll, qt5gui.dll etc) in the same directory of my exe. But I can't figure out a way this time.
After static build of Qt, the DLLs in the plugins/platforms/ folder are gone and they are replaced by libs. I have also tried to statically link with qwindows.lib but to no avail.
Any idea?
Regards.
To check what DLL are needed to deploy your application on Windows, use dependency Walker (http://www.dependencywalker.com/).
According to the documentation page Qt for Windows - Deployment some DLL are required to deploy a Qt application on Windows platforms:
qwindows.dll
icudtXX.dll
icuinXX.dll
icuucXX.dll
libGLESv2.dll
libEGL.dll
Depending on the compiler you use to compile the application, some other libraries may be required:
MSVC specific libraries:
msvcrXX.dll
msvcpXX.dll
MinGW specific libraries
libgcc_s_dw2-1.DLL
libstdc++-6.dll
Note: in all these files, replace XX by the current version of the DLL on your system.
If you didn't build Qt statically (default), you will also need Qt5 DLL depending on Qt module you use in your application. Example:
Qt5Core.dll
Qt5Test.dll
Qt5Network.dll
etc.
All these DLL can be found in "bin" folder, under your Qt installation dir.
EDIT
Recently, Qt developers created a tool named windeployqt.exe which helps you to gather all required library to deploy an application:
Usage: windeployqt [options] [file]
Qt Deploy Tool 5.3.0
The simplest way to use windeployqt is to add the bin directory of your Qt
installation (e.g. <QT_DIR\bin>) to the PATH variable and then run:
windeployqt <path-to-app-binary>
If ICU, ANGLE, etc. are not in the bin directory, they need to be in the PATH
variable. If your application uses Qt Quick, run:
windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>
Options:
-?, -h, --help Displays this help.
-v, --version Displays version information.
--dir <directory> Use directory instead of binary directory.
--libdir <path> Copy libraries to path.
--debug Assume debug binaries.
--release Assume release binaries.
--force Force updating files.
--dry-run Simulation mode. Behave normally, but do not
copy/update any files.
--no-plugins Skip plugin deployment.
--no-libraries Skip library deployment.
--qmldir <directory> Scan for QML-imports starting from directory.
--no-quick-import Skip deployment of Qt Quick imports.
--no-translations Skip deployment of translations.
--no-system-d3d-compiler Skip deployment of the system D3D compiler.
--compiler-runtime Deploy compiler runtime (Desktop only).
--no-compiler-runtime Do not deploy compiler runtime (Desktop only).
--webkit2 Deployment of WebKit2 (web process).
--no-webkit2 Skip deployment of WebKit2.
--json Print to stdout in JSON format.
--list <option> Print only the names of the files copied.
Available options:
source: absolute path of the source files
target: absolute path of the target files
relative: paths of the target files, relative
to the target directory
mapping: outputs the source and the relative
target, suitable for use within an
Appx mapping file
--verbose <level> Verbose level.
Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth clucene concurrent core declarative designercomponents designer gui
clucene qthelp multimedia multimediawidgets multimediaquick network nfc opengl
positioning printsupport qml quick quickparticles script scripttools sensors
serialport sql svg test widgets winextras xml xmlpatterns
Arguments:
[file] Binary or directory containing the binary.
I just had the same problem, so here is my solution:
First of course build QT with the -static parameter.
Add the following libs to your build:
Qt5PlatformSupport.lib
qwindows.lib
imm32.lib
Add the following path to your library paths:
$(QTDIR)\plugins\platforms
In your code (preferably main.cpp) add the following line:
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
The resulting build should not depend on any qt-related dlls.
If you are using libGLESv2.dll, then you must include libEGL.dll, too. See
Deploying Qt C++ Application from Visual Studio qwindows.dll error
It's a Qt platform plugin issue. Using qt.conf resolved the problem for me on MacOS.
It doesn't matter if you link Qt staticly on not.
I tried to staticly link to libqcocoa.a (or qwindows.lib) without success. I will let you know if i succeed.
Just do the following steps:
Go to bin folder in your Qt installation directory
Copy all files with .dll extension
Past them to C:\Windows\System32 for 32 bits or C:\Windows\syswow64 for 64 bits.
Tada! you will never see that irritating message again

How to create executable file for a Qt Application?

I've been searching on the internet for some useful and clear information about this, it's annoying that such a trivial thing is so hard to do.
What I need is to create an executable file for my Qt project, in order to run it in other computers. My project runs nicely in the Qt Creator, but when I try to run the executable created in the release folder I get errors about some dll missing, and though I have put all of them in the same directory of my .exe I now got some errors about entrypoints in procedures inside the dll (QtCore4.dll).
The solution looks like to be a static linking, I've found many information about it, but none of them really helped me. Here is what I have tried so far:
Using the executable created in the release folder as I said above.
Static Linking, following this tutorial (and many others, all almost the same thing): http://doc.qt.io/qt-4.8/deployment-windows.html but I get the following error during the "configure -static": NMAKE : fatal error U1077: '"c:\Arquivos de programas\Microsoft Visual Studio 9.
0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
Building qmake failed, return code 2
For that I couldn't find any solution, so here I am, just trying to create an executable file for my Qt project, hope you guys can give me some light here.
Basically you have to look for mingw subfolder deep into qt tree, where qt utilities reside, and copy needed dll's.
These are the steps I follow, based upon QT 4.7.4, for packaging the application with correct shared libraries.
Let's say you've installed QT under c:\qtsdk
Open your project, and compile it in release mode.
Go to this directory: C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin -- it contains all shared libraries. Debug libraries end with a "d" -- frex, QtCore.dll is release version, while QtCoreD.dll is debug version
Copy at least these files into your release directory (where your .exe lies)
mingwm10.dll
libgcc_s_dw2-1.dll
QtCore4.dll
QtGui4.dll
I just built, tested and deployed a dummy project this way.
Do these steps:
1- Open qt command-line window.
2- Go to the directory which .exe file exists (using cd command).
3- Run windeployqt.exe --quick . command
4- Run your exe file and enjoy it!
This video is great
Here is what I did and I got it to work after some time;after making sure that your program builds inside Qtcreator,go to the directory that contains your exe and double click on it.(I'm using windows and don't know if it is the same on other platforms).A window should popup telling you which .dll is missing.Go to the directory where Qt is installed and type the exact name in the search bar(top-right in Windows 7) and the dll should show up in search results.Right click and choose open file location.Copy the file where your exe is located .Double click on the exe again.If another .dll is missing repeat the same thing until none is missing.In the end your program should run.
Hope this helps.
So you downloaded Qt SDK and you want to link Qt libraries statically into you application, right?
First of all, if you link statically, you don't need any Qt*.dll to be present anywhere because it is built into the application. So that alone means that your application is built using dynamic linking.
From my experience, that safest way to get it all working is:
Download Qt sources, build and install them with nmake ( using Visual Studio Command Prompt from Menu Start -> Application -> Visual Studio 2008 ). Just remember that the size of the statically linked application is dependent on the size of the *.libs and these are dependent on the pre-build configuration, for example, you can minimize the size of you application by turning off some features ( this is an example config for MacOSX, just watch out for the ones specific for Windows and add proper plaftorm - see configure.exe --help for details ):
./configure -arch x86 -platform macx-g++ --universal -cocoa -debug-and-release -opensource -static -fast -no-accessibility -no-sql-sqlite -no-qt3support -no-opengl -no-openvg -qt-zlib -no-gif -no-libmng -qt-libmng -no-libtiff -qt-libjpeg -no-3dnow -sse -no-sse2 -no-openssl -no-dbus -no-phonon -no-multimedia -no-audio-backend -webkit -no-script -no-scripttools -no-declarative -nomake demos -nomake examples -no-exceptions -no-accessibility -confirm-license
Install, setup and use Visual Studio Add-In for you Qt project (here ).
Good Luck! :)
I share with you my solution. On my qt creator 4.2.1, I did these steps:
1) - I clicked on release and it generated a folder in my project directory like that: C:\Users\Samir\Documents\Qt-Projects\build-Calculator-Desktop_Qt_5_8_0_MinGW_32bit-Release.
2) - I opened the terminal qt 5.8 for desktop and I navigated to my project directory where the .exe located.
3) - Finally, I ran the command line windeployqt.exe --quick .. This command allowed me to generate the libraries which were missing.
And now everything works fine!