Compile a Qt Application without .dll dependencies
-
Hello everyone!
I'm relatively new to Qt and generally I really like the framework and the editor.
Just one thing that bugs me: When I compile a Qt application on my windows PC, the generated .exe requires tons of .dlls. I know, that's the Qt library stuff, but what I'm looking for is a way to create one single .exe file that can be distributed to others without them having to install Qt or copying / downloading the bunch of dlls.
Is there a way to do this? -
Hi and welcome to devnet
You have to compile Qt libs on your own see this wiki
You can also distribute your application with dlls see this wiki.In general there is a major difference between licenses for static and dynamic linking. You might want to check out licensing.
-
OK, so I downloaded that script and executed it and it ran into an error.
This is the log:Building static Qt version 5.5.1 Using MinGW from C:\MinGW Downloading http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.7z ... Expanding C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1.7z ... 7-Zip [64] 15.12 : Copyright (c) 1999-2015 Igor Pavlov : 2015-11-19 Scanning the drive for archives: 1 file, 312170178 bytes (298 MiB) -- Path = C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1.7z Type = 7z Physical Size = 312170178 Headers Size = 1755218 Method = LZMA:24 BCJ Solid = + Blocks = 3 Everything is Ok Folders: 14226 Files: 139086 Size: 1641714645 Compressed: 312170178 Patching C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\mkspecs\win32-g++\qmake.conf ... + cd qtbase + C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\configure.bat -top-level -static -debug-and-release -platform win32-g++ -prefix C:\Qt\Static\5.5.1 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests This is the Qt for Windows Open Source Edition. You have already accepted the terms of the license. Creating qmake... g++ -c -o project.o -DUNICODE -ffunction-sections -g -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/library -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/unix -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/win32 -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/mac -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/integrity -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore/5.5.1 -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore/5.5.1/QtCore -I../src/corelib/global -DHAVE_QCONFIG_CPP -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\mkspecs\win32-g++ -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/tools/shared -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY -DQT_NO_STANDARDPATHS C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/project.cpp Makefile:201: recipe for target 'project.o' failed mingw32-make: *** [project.o] Error 1 del /f project.o option.o property.o main.o ioutils.o proitems.o qmakevfs.o qmakeglobals.o qmakeparser.o qmakeevaluator.o qmakebuiltins.o makefile.o unixmake2.o unixmake.o mingw_make.o winmakefile.o projectgenerator.o meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o msvc_vcproj.o msvc_vcxproj.o msvc_nmake.o msvc_objectmodel.o msbuild_objectmodel.o cesdkhandler.o qtextcodec.o qutfcodec.o qstring.o qstring_compat.o qstringbuilder.o qtextstream.o qiodevice.o qdebug.o qmalloc.o qglobal.o qarraydata.o qbytearray.o qbytearraymatcher.o qdatastream.o qbuffer.o qlist.o qfiledevice.o qfile.o qfilesystementry.o qfilesystemengine.o qfsfileengine.o qfsfileengine_iterator.o qregexp.o qvector.o qbitarray.o qdir.o qdiriterator.o quuid.o qhash.o qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o qmap.o qmetatype.o qsettings.o qsystemerror.o qlibraryinfo.o qvariant.o qvsnprintf.o qlocale.o qlocale_tools.o qlinkedlist.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o qlogging.o qjson.o qjsondocument.o qjsonparser.o qjsonarray.o qjsonobject.o qjsonvalue.o qfilesystemengine_win.o qfilesystemiterator_win.o qfsfileengine_win.o qlocale_win.o qsettings_win.o qsystemlibrary.o registry.o C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\qmake\project.o konnte nicht gefunden werden g++ -c -o project.o -DUNICODE -ffunction-sections -g -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/library -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/unix -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/win32 -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/mac -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/integrity -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore/5.5.1 -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\include/QtCore/5.5.1/QtCore -I../src/corelib/global -DHAVE_QCONFIG_CPP -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\mkspecs\win32-g++ -IC:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/tools/shared -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY -DQT_NO_STANDARDPATHS C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/project.cpp Makefile:201: recipe for target 'project.o' failed mingw32-make: *** [project.o] Error 1 Building qmake failed, return code 2 mingw32-make: *** No targets specified and no makefile found. Stop. mingw32-make: *** No rule to make target 'install'. Out-File : Ein Teil des Pfades "C:\Qt\Static\5.5.1\mkspecs\win32-g++\qmake.conf" konnte nicht gefunden werden. In C:\Users\Julian\Desktop\windows-build-qt-static.ps1:178 Zeichen:6 + "@ | Out-File -Append $File -Encoding Ascii + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand Drücken Sie die Eingabetaste, um den Vorgang fortzusetzen...:
Do you know what happened here and what I can do about this?
-
This script is new. I have never used it so far.
In the past you had to download the zip archive and unzipped it on your own.
There should be all the content already unzipped and readily available for compilation.
Is a file "C:\Qt\Static\5.5.1\mkspecs\win32-g++\qmake.conf" already there?
This seems to be missing. -
@koahnig It seems like the build process failed at some point and terminated completely (Don't know why). Then the script tries to do some final patches, which fail because the files are not existent.
Do you have any idea what I can do instead?
-
No it isnt. The folder Qt\Static\5.5.1 is completely empty.
-
@Julius-Aetherwing
I have never used that script. In the output I do not see where it broke.Basically it was not very difficult to do all the stuff without the script. However, I cannot find the proper wiki entries anymore.
Only this one I have googled.
The configure is basically the essential part after unzippuing the stuff. The configure does give some guidelines during its execution.
However, I am not completely sure if this is enough to through it completely. -
@koahnig OK, so I looked into the script and it does relatively simple stuff.
- Downloading and extracting the code,
- patching the file \qtbase\mkspecs\win32-g++\qmake.conf, adding this to the end:
# [QT-STATIC-PATCH] QMAKE_LFLAGS += -static -static-libgcc QMAKE_CFLAGS_RELEASE -= -O2 QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer DEFINES += QT_STATIC_BUILD
- Calling configure with these arguments: (where $QtDir is C:\Qt\Static\5.5.1)
configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests
- Calling
mingw32-make -k -j4
- And calling
mingw32-make -k install
- Finally patching the qmake.conf file again, this time adding this:
CONFIG += static
I tried to invoke configure with the arguments mentioned in the other article you linked, but it yelled at me saying there is no option -no-exceptions.
Running without this option printed something, but errored saying this:In file included from C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase/qmake/generators/makefiledeps.cpp:40:0: C:\Qt\Static\src\qt-everywhere-opensource-src-5.5.1\qtbase\mkspecs\win32-g++/qplatformdefs.h:47:19: fatal error: tchar.h: No such file or directory #include <tchar.h> ^ compilation terminated. Makefile:222: recipe for target 'makefiledeps.o' failed mingw32-make: *** [makefiledeps.o] Error 1 Building qmake failed, return code 2
Running with the options in the script (which is where it failed before, I think) lead to the same error.
-
You don't need to distribute all the Qt dll files with your application (your reference to 'tonnes of dll's'). You need the platform plugin folder (with 'qwindows.dll') and a few others such as Qt5Widgets, Qt5Core, Qt5Gui, and two or three for the c++ runtime (mingw dependencies). Usually it is under 10 files.
You likely should compile Qt yourself from source and remove a few things you probably don't need. The 'icu*.dll' files that are related to webkit come to mind. These files are huge relatively speaking.
For Windows I can usually get a basic application to be around 15 mb (total of all files required) on Windows.
There is a utility program from Microsoft called 'depends.exe' (Dependency Viewer) that you can use to see which DLL files your application requires. At a minimum if you run the program Windows will tell you which dll file it couldn't find (don't do this on your development pc as you may have dll files or path settings that make this unreliable).
-
@Julius-Aetherwing
My guess is that this may have something to do with the path environment. I believe there were a couple of settings to be made. However, as mentioned before I could not find the wiki entries, they were holding more information. Also the configure stuff may have changed.When you are right that the failure might be in the same place as with the script, it may also be that there is a setting missing you should added upfront.
My static compilations go a couple of years back. With Qt 5 I did not have the need for static libs anymore.
You may also reconsider and follow @Rondog advice. He is completely right that there are not so many dlls. Furthermore, you have to be aware of the license implication when using a static compilation.
-
@Rondog You surely have a point here.
I think, i'm trying the dll stuff again, maybe this will lead to a reasonable application size..
EDIT: Just recognized that the only the "Debug" dlls are that huge in size, the normal "Release" dlls are about a fifth or a tenth of the size.. That's great :)
-
You should check this: http://doc.qt.io/qt-5/windows-deployment.html
Especially the "The Windows Deployment Tool" part.