Creating a truly, completely static Qt 5 framework and application (post Qt 5.8)

As the name suggests, the goal is to create the Qt framework and Qt application in such a way as to create a single executable binary with no external dependencies.

My motivation is that since the build system was "improved" in Qt 5.8, I really haven't been able to complete a successful static build of Qt. And even before that, creating a static Qt framework was easy, but didn't actually create an executable binary with no external dependencies. There were still a lot of libraries that needed to be linked, and only the Qt libraries were statically linked.

Going back to the days before Qt 5.8, I was able to get a successful static Qt build with the following configuration:

configure -c ++ std c ++ 11 -prefix E: \ Qt \ Qt58s -platform win32-g ++ -release -opensource -static -qt-zlib -qt-libpng -qt-libjpeg -qt-freetype -no-compile- examples -no-icu -opengl desktop -skip qtscript -nomake examples -nomake tests -skip qtwayland -skip qtwebview -skip qtwebengine -skip qtwebchannel -no-qml-debug -confirm-license -LE: \ msys64 \ mingw64 \ lib -qt -sql-psql -qt-sql-mysql -l mysqlclient -IE: \ msys64 \ mingw64 \ include \ mariadb

To summarize the configuration, it was limited to the release of assemblies, the absence of any libraries provided by the platform, and the ability to use those related to Qt. Removing icu as a significant source of binary bloat, as well as tests and examples to reduce build times, and a web engine not built with GCC. In addition, the configuration includes support for the postgres and mysql drivers, the latter of which is via the mariadb client library.

This build configuration, as always, was done for a few minor versions of Qt 5, but it never created executables without dependencies. I still had to manually link the psql and mysql libraries in the PRO file, and I still had to include at least the gcc runtime libraries.

Although it was proven to successfully link static files statically by adding QMAKE_LFLAGS += -static-libgcc -static-libstdc++

to the PRO file, this only handled those specific libraries.

On the "large scale", adding static linker flags with using QMAKE_LFLAGS += -static

never resulted in a successful build, but instead caused bugs and conflicts between different libraries to be linked with an internal link to the same libraries.

But again, then Qt 5.8 came along and re-configured the build system to improve it. And like many "enhancements" it really crashed without a viable way to select third party libraries in configuration, instead having to manually hack various JSON configuration files.

This bug has since been fixed, leading to renewed my efforts to create a fully static build of Qt. Now using the following configuration:

configure -prefix E: \ Qt \ Qt591s -C ++ std C ++ 11 -platform win32-g ++ -release -opensource -static -static-runtime -qt-zlib -qt-libpng -qt-libjpeg -qt-freetype - no-compile-examples -no-icu -opengl desktop -skip qtscript -nomake examples -nomake tests -skip qtwayland -skip qtwebview -skip qtwebengine -skip qtwebchannel -no-qml-debug -confirm-license -sql-psql -sql- mysql MYSQL_INCDIR = E: \ msys64 \ mingw64 \ include \ mariadb MYSQL_LIBDIR = E: \ msys64 \ mingw64 \ lib MYSQL_LIBS = "- l mysqlclient" -LE: \ msys64 \ mingw64 \ Lib

The difference is in the use of new syntax for specifying third party libraries and adding a flag -static-runtime

. Which later turned out to be the cause of the configuration failure because mysql was unable to resolve indirect dependencies, which supposedly should work if the entire dependency tree is explicitly included.

Wanting to get a working build, I just dropped it -static-runtime

, and indeed, I finally have a working config. But I haven't been there yet, as the build failed, with no meaningful output to understand why.

The next step was to try to limit the compilation output with a config flag -silent

, which unfortunately resulted in a build failure of 5 seconds during compilation, showing a long-standing bug that prevented this flag from being used with GCC, regardless of whether you are building a Qt or a Qt application.

Then I tried to create a single thread in the hopes that I would get less clutter and maybe even some understanding of why the assembly is not working. Alas, to no avail. All I could get from the output was that the build failed in the libjpg phase. This prompted me to remove all the flags defining the use of linked libraries that got me through libjpg, only to make the build fail on the platform plugin, just as little understanding why.

As a last resort, I tried to remove most of the potentially problematic configuration flags, including static build, in the hopes of at least getting a successful "regular build" that also failed:

Configure -prefix E: \ Qt \ Qt591test -C ++ std C ++ 11 -platform win32-g ++ -release -opensource -no-compile-examples -no-icu -opengl desktop -skip qtscript -nomake examples -nomake tests - skip qtwayland -skip qtwebview -skip qtwebengine -skip qtwebchannel -no-qml-debug - validate-license

Leaving me with the following output:

        g++ -fno-keep-inline-dllexport -pipe -O2 -std=c++11 -fno-exceptions -Wex
tra -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -dM -E -o .m
oc\release\moc_predefs.h e:\share\qt-everywhere-opensource-src-5.9.1\qtbase\mksp
ecs\features\data\dummy.cpp
        g++ -c -fno-keep-inline-dllexport -pipe -O2 -std=c++11 -fno-exceptions -
Wextra -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -DUNICODE
 -DQT_NO_CAST_FROM_ASCII -DLIBEGL_NAME=libEGL -DLIBGLESV2_NAME=libGLESv2 -DQT_NO
_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -
DQT_EVENTDISPATCHER_SUPPORT_LIB -DQT_ACCESSIBILITY_SUPPORT_LIB -DQT_FONTDATABASE
_SUPPORT_LIB -DQT_THEME_SUPPORT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -IE:\share\qt-eve
rywhere-opensource-src-5.9.1\qtbase\src\plugins\platforms\direct2d -I. -IE:\shar
e\qt-everywhere-opensource-src-5.9.1\qtbase\src\plugins\platforms\windows -IE:\s
hare\qt-everywhere-opensource-src-5.9.1\qtbase\src\3rdparty\wintab -IE:\share\qt
-everywhere-opensource-src-5.9.1\qtbase\include -IE:\share\qt-everywhere-opensou
rce-src-5.9.1\qtbase\include\QtEventDispatcherSupport -IE:\share\qt-everywhere-o
pensource-src-5.9.1\qtbase\include\QtEventDispatcherSupport\5.9.1 -IE:\share\qt-
everywhere-opensource-src-5.9.1\qtbase\include\QtEventDispatcherSupport\5.9.1\Qt
EventDispatcherSupport -I..\..\..\..\include -I..\..\..\..\include\QtEventDispat
cherSupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtAcces
sibilitySupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtA
ccessibilitySupport\5.9.1 -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\i
nclude\QtAccessibilitySupport\5.9.1\QtAccessibilitySupport -I..\..\..\..\include
\QtAccessibilitySupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\inc
lude\QtFontDatabaseSupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\
include\QtFontDatabaseSupport\5.9.1 -IE:\share\qt-everywhere-opensource-src-5.9.
1\qtbase\include\QtFontDatabaseSupport\5.9.1\QtFontDatabaseSupport -I..\..\..\..
\include\QtFontDatabaseSupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtb
ase\include\QtThemeSupport -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\
include\QtThemeSupport\5.9.1 -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbas
e\include\QtThemeSupport\5.9.1\QtThemeSupport -I..\..\..\..\include\QtThemeSuppo
rt -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtGui\5.9.1 -IE:
\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtGui\5.9.1\QtGui -I..\
..\..\..\include\QtGui\5.9.1 -I..\..\..\..\include\QtGui\5.9.1\QtGui -IE:\share\
qt-everywhere-opensource-src-5.9.1\qtbase\include\QtGui -I..\..\..\..\include\Qt
Gui -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtCore\5.9.1 -I
E:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtCore\5.9.1\QtCore -
I..\..\..\..\include\QtCore\5.9.1 -I..\..\..\..\include\QtCore\5.9.1\QtCore -IE:
\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtCore -I..\..\..\..\in
clude\QtCore -I.moc\release -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase
\mkspecs\win32-g++ -o .obj\release\moc_qwindowsdirect2dnativeinterface.o .moc\re
lease\moc_qwindowsdirect2dnativeinterface.cpp
        g++ -Wl,-s -shared -Wl,-subsystem,windows -Wl,--out-implib,E:\tmpbuild\q
tbase\plugins\platforms\libqdirect2d.a -o ..\..\..\..\plugins\platforms\qdirect2
d.dll object_script.qdirect2d.Release  -ldwmapi -ld2d1 -ld3d11 -ldwrite -lVersio
n -lwinspool -limm32 -lwinmm -loleaut32 -lshlwapi -lshell32 -LE:\tmpbuild\qtbase
\lib E:\tmpbuild\qtbase\lib\libQt5EventDispatcherSupport.a E:\tmpbuild\qtbase\li
b\libQt5AccessibilitySupport.a E:\tmpbuild\qtbase\lib\libQt5FontDatabaseSupport.
a -lole32 -ladvapi32 -luuid E:\tmpbuild\qtbase\lib\libqtfreetype.a E:\tmpbuild\q
tbase\lib\libqtlibpng.a -lz E:\tmpbuild\qtbase\lib\libQt5ThemeSupport.a -lglu32
-lopengl32 -lgdi32 -luser32 E:\tmpbuild\qtbase\lib\libQt5Gui.a E:\tmpbuild\qtbas
e\lib\libQt5Core.a .obj\release\qdirect2d_resource_res.o
        windres -i qjpeg_resource.rc -o .obj\release\qjpeg_resource_res.o --incl
ude-dir=. -DUNICODE -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_EXCEPTIONS
-DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB
        E:\tmpbuild\qtbase\bin\moc.exe -DUNICODE -DQT_NO_NARROWING_CONVERSIONS_I
N_CONNECT -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LI
B --include .moc/release/moc_predefs.h -IE:/share/qt-everywhere-opensource-src-5
.9.1/qtbase/mkspecs/win32-g++ -IE:/share/qt-everywhere-opensource-src-5.9.1/qtba
se/src/plugins/imageformats/jpeg -IE:/share/qt-everywhere-opensource-src-5.9.1/q
tbase/src/3rdparty/libjpeg -IE:/share/qt-everywhere-opensource-src-5.9.1/qtbase/
include/QtGui/5.9.1 -IE:/share/qt-everywhere-opensource-src-5.9.1/qtbase/include
/QtGui/5.9.1/QtGui -IE:/tmpbuild/qtbase/include/QtGui/5.9.1 -IE:/tmpbuild/qtbase
/include/QtGui/5.9.1/QtGui -IE:/share/qt-everywhere-opensource-src-5.9.1/qtbase/
include -IE:/share/qt-everywhere-opensource-src-5.9.1/qtbase/include/QtGui -IE:/
tmpbuild/qtbase/include -IE:/tmpbuild/qtbase/include/QtGui -IE:/share/qt-everywh
ere-opensource-src-5.9.1/qtbase/include/QtCore/5.9.1 -IE:/share/qt-everywhere-op
ensource-src-5.9.1/qtbase/include/QtCore/5.9.1/QtCore -IE:/tmpbuild/qtbase/inclu
de/QtCore/5.9.1 -IE:/tmpbuild/qtbase/include/QtCore/5.9.1/QtCore -IE:/share/qt-e
verywhere-opensource-src-5.9.1/qtbase/include/QtCore -IE:/tmpbuild/qtbase/includ
e/QtCore -I. -IE:/msys64/mingw64/include/c++/7.1.0 -IE:/msys64/mingw64/include/c
++/7.1.0/x86_64-w64-mingw32 -IE:/msys64/mingw64/include/c++/7.1.0/backward -IE:/
msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include -IE:/msys64/mingw64/incl
ude -IE:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed -IE:/msys
64/mingw64/x86_64-w64-mingw32/include E:\share\qt-everywhere-opensource-src-5.9.
1\qtbase\src\plugins\imageformats\jpeg\main.h -o .moc\release\moc_main.cpp
        g++ -c -fno-keep-inline-dllexport -pipe -O2 -std=c++11 -fno-exceptions -
Wextra -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -DUNICODE
 -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_
PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -IE:\share\qt-everywhere-opensource-src-5.9.1\
qtbase\src\plugins\imageformats\jpeg -I. -IE:\share\qt-everywhere-opensource-src
-5.9.1\qtbase\src\3rdparty\libjpeg -IE:\share\qt-everywhere-opensource-src-5.9.1
\qtbase\include\QtGui\5.9.1 -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase
\include\QtGui\5.9.1\QtGui -I..\..\..\..\include\QtGui\5.9.1 -I..\..\..\..\inclu
de\QtGui\5.9.1\QtGui -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\includ
e -IE:\share\qt-everywhere-opensource-src-5.9.1\qtbase\include\QtGui -I..\..\..\
..\include -I..\..\..\..\include\QtGui -IE:\share\qt-everywhere-opensource-src-5
.9.1\qtbase\include\QtCore\5.9.1 -IE:\share\qt-everywhere-opensource-src-5.9.1\q
tbase\include\QtCore\5.9.1\QtCore -I..\..\..\..\include\QtCore\5.9.1 -I..\..\..\
..\include\QtCore\5.9.1\QtCore -IE:\share\qt-everywhere-opensource-src-5.9.1\qtb
ase\include\QtCore -I..\..\..\..\include\QtCore -I.moc\release -IE:\share\qt-eve
rywhere-opensource-src-5.9.1\qtbase\mkspecs\win32-g++ -o .obj\release\moc_main.o
 .moc\release\moc_main.cpp
        g++ -Wl,-s -shared -Wl,-subsystem,windows -Wl,--out-implib,E:\tmpbuild\q
tbase\plugins\imageformats\libqjpeg.a -o ..\..\..\..\plugins\imageformats\qjpeg.
dll object_script.qjpeg.Release  -lglu32 -lopengl32 -lgdi32 -luser32 -LE:\tmpbui
ld\qtbase\lib E:\tmpbuild\qtbase\lib\libQt5Gui.a E:\tmpbuild\qtbase\lib\libQt5Co
re.a .obj\release\qjpeg_resource_res.o
jom: E:\tmpbuild\qtbase\Makefile [sub-qmake-qmake-aux-pro-make_first] Error 2
jom: E:\tmpbuild\Makefile [module-qtbase-make_first] Error 2

      

At this point, I would like to reiterate that prior to Qt 5.8 I was getting successful builds over multiple versions using the same toolchain.

My main development platform is windows where I am using MSYS2 as my build environment and main toolchain using GCC 5.3.0. I also used the dev libs provided by MSYS2 for psql and mariadbclient to save the need to build them myself. I am targeting android and linux as well, so the question is specific to those 3 platforms. I am not targeting macos or ios, so while I am not directly influencing me as an OP, information on those platforms will probably still be usable.

So, anyone who can handle news like me due to the difficulty of getting a truly static build of Qt?

I am currently struggling with the latest version, at the time it is 5.9.1, but this question should remain relevant for future versions as well, which may introduce their own quirks.

+3


source to share


1 answer


After a month, I was able to make some progress, not quite where the OP's heading is, but still I can now consistently build Qt in static or dynamic configuration using my own SQL libraries and working SQL.

In reality, the culprit was jom

, which consistently fails in different parts depending on the configuration. I tried several versions and they all failed. I tried several different, more conservative configuration options, I even tried the painfully slow single-threaded build. All failed.



However, using it mingw32-make

works with 100% success, I accidentally found that as a last try, after using it jom

for many years, because it is claimed to be faster. However, it make

also supports parallel builds using the same parameter -j coreCount

, so Qt fast builds are still an option without jom

.

I will come back and update this when I get more progress ... the saga continues.

+1


source







All Articles