5

How to statically compile Qt with OpenSSL support on Windows (with MinGW compiler) The desired 'outcome' of this Qt build is to build and ship a portable Qt application with built-in SSL support.

So this is an age old problem with a multitude of questions on this topic, yet very few solutions exist that solves the problem. Some of these questions (and problems):

there are many more

and some of my own questions (using OpenSSL v1.1.1d & Qt 5.13 with MinGW ):

Most of these questions do not have answers, and those answers provided (obviously) did not help in compiling, due to some error output or simply OpenSSL was never linked (built into the portable/binary application), or many other errors.

Further, there appears to be alot of confusion about using -ssl, -openssl-linked, -openssl and what each means. Also, if one should use -L/path/to/libs/static -l library1 -l library2 vs using the OPENSSL_HOME env variable and specify the path to headers & static / linked libraries, etc

Please note:

Ideally, in compiling, specific instructions for libraries would be required such as OpenSSL v1.0.2 or OpenSSL v1.1 and the qmake arguments in building a static Qt with those specific libraries in addition to things that should be considered during the build process.

What does Qt say?

Qt has provide some help in the form of these 2 posts:

The aim of this question is to give a detailed explanation and step-wise method in allowing those who need to compile a static Qt version with SSL some support and direction.

This is an unnatural "question", but having seen so many questions with no/very few solutions for cherrypicked cases in each specific question makes a general solution very difficult to obtain.

I am posting this question in hopes of a general solution being made available that could benefit all.

CybeX
  • 2,060
  • 3
  • 48
  • 115
  • Have you seen [this answer](https://stackoverflow.com/a/44853006/176769)? Different compiler though. – karlphillip Jun 17 '20 at 12:59
  • @karlphillip yeah - you should find it in either one of my links up in the post or one of the cited links in one of my links (questions) above. I have tried it, and posted a response to it. For the record, I would prefer, a clean & fresh windows with a build solution from scratch, but this is very hard near-impossible to source / come by. – CybeX Jun 17 '20 at 14:31
  • That link is from an answer of mine: the answer has received no comments, its not on your list and I can't find your name anywhere on that page. Just saying :) – karlphillip Jun 17 '20 at 16:18
  • @karlphillip the suggested openssl flags & locations I have posted my results for this with MinGW - these failed to build. The only build that was ever successful was w/o openssl. I tried almost every combination of the ssl flags with static openssl builds, openssl with same mingw compiler builds, etc - for more info (you will find these in the links). I remember seeing your post a while back, but you used MSVC while I was limited to MinGW hence, I would still prefer using this MinGW (the reasons escape me for the MinGW pref i.e. some specific advantages over MSVC). – CybeX Jun 17 '20 at 22:06

1 Answers1

1

I just noticed this question just recently, so I haven't had time yet to write complete step-by-step instructions from the ground up, but I was able to do a static build of qt-5.15.0 in my environment which is based on MSYS2 shell together with MinGW-w64 with GCC 10 personal build from http://winlibs.com/ with all the prerequisites already compiled in the same environment.

The version of openssl was 1.1.1g built like this (static and shared libraries):

# location of Perl
PERLDIR=/d/Prog/Perl/strawberry-perl-5.30.0.1-64bit-portable/perl
# install destination
INSTALLPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# for 32-bit replace mingw64 with mingw in the next line
./Configure --prefix=$INSTALLPREFIX threads shared zlib-dynamic -DOPENSSL_NO_CAPIENG mingw64 &&
make &&
PATH=$PERLDIR/bin:$PATH make -j1 install OPENSSLDIR_dir=$INSTALLPREFIX &&
strip $INSTALLPREFIX/bin/*.exe $INSTALLPREFIX/bin/*.dll &&
cp -f $INSTALLPREFIX/lib/libcrypto.a $INSTALLPREFIX/lib/libeay32.a && 
cp -f $INSTALLPREFIX/lib/libcrypto.dll.a $INSTALLPREFIX/lib/libeay32.dll.a && 
cp -f $INSTALLPREFIX/lib/libssl.a $INSTALLPREFIX/lib/libssleay32.a && 
cp -f $INSTALLPREFIX/lib/libssl.dll.a $INSTALLPREFIX/lib/libssleay32.dll.a && 
cp -f ms/applink.c $INSTALLPREFIX/include/openssl/ && 
echo Success

Here are the steps I did to do the static build of qt-5.15.0:

# location of Python
PY2DIR=/d/Prog/Python/WinPython-64bit-2.7.13.1Zero/python-2.7.13.amd64
# location of all the prerequisites
MINGWPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# install destination
INSTALLPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# fix missing SHARE_INFO_1 in qtbase/src/corelib/io/qfilesystemengine_win.cpp 
echo "#include <levmar.h>" | gcc -E -xc - &> /dev/null && sed -i.bak -e "s/\(#\s*include <\)lm\.h\(>\)/\1levmar.h\2\n\1lmshare.h\2\n\1lmapibuf.h\2/" qtbase/src/corelib/io/qfilesystemengine_win.cpp
# avoid using missing debug ICU libraries in static builds
sed -i.bak -e "s/\(lsicu..\)d/\1/g" qtbase/src/corelib/configure.json
# configure
mkdir -p build_static &&
cd build_static &&
PATH=$PATH:$PY2DIR ../configure -platform win32-g++ -prefix $INSTALLPREFIX/qt -opensource -confirm-license -release -static -no-pch -no-rpath -strip -skip "qtserialbus" -qpa windows -gif -sql-odbc -sql-sqlite -opengl desktop -icu -system-pcre -dbus -system-sqlite -system-zlib -system-libpng -system-libjpeg -system-doubleconversion -system-freetype -system-harfbuzz -libproxy -system-proxies -openssl -openssl-linked -no-xcb -no-compile-examples -skip qtwebengine -nomake examples -system-proxies -plugin-manifests -pkg-config -I $MINGWPREFIX/include/freetype2 -I $MINGWPREFIX/include/mariadb &&
sed -i.bak -e "s/\(-lclang\)\.a/\1 -lpthread/" qttools/src/qdoc/Makefile.* &&
cd .. &&
# build
(
 PATH=$PATH:$PY2DIR mingw32-make -Cbuild_static release QMAKE_CXXFLAGS="-fcommon" QMAKE_LFLAGS="-Wl,-allow-multiple-definition" || (
  make -Cbuild_static/qttools/src/qdoc &&
  PATH=$PATH:$PY2DIR mingw32-make -Cbuild_static release QMAKE_CXXFLAGS="-fcommon" QMAKE_LFLAGS="-Wl,-allow-multiple-definition"
)) &&
# workaround for missing qmake.exe
cp build_static/qtbase/bin/qmake.exe build_static/qtbase/qmake/ &&
make -Cbuild_static install &&
# manually create qt.conf
echo "[Paths]" > $INSTALLPREFIX/qt/bin/qt.conf &&
echo "Prefix=../../qt" >> $INSTALLPREFIX/qt/bin/qt.conf &&
echo Success

I have tested the result by building KeePassXC (https://github.com/keepassxreboot/keepassxc/archive/2.5.4.tar.gz) against it and the resulting package had no Qt DLLs at all and it ran fine.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • What do you mean with Python specific? My build is general for use with whatever needs it. As a test I tried to build sqlitebrowser v3.12.0-rc1 against this static Qt, and it built and ran just fine. – Brecht Sanders Jun 11 '20 at 15:20
  • 1
    what are the requirements for this - the script itself may work for one individual but not for another, also, I see python is mentioned here too. Could you please provide more information about how you went about building it, what did you use, your environment variables, etc as this is also an issue that affects many of these builds, it works for one person but not another due to minor configuration changes. A more detailed solution is required for me to be able to test it and further to accept it. Thank you. – CybeX Jun 12 '20 at 16:33
  • I'm working on a project to build opensource libraries (shared+static) and applications and all of their dependancies (currently over 1600 of them) from scratch. The plan is to publish this work on http://winlibs.com/ which is currently only home to my personal build of MinGW-w64. Once I have streamlined everything to make it easily reproducible I will publish everything, but I'm not there yet. I do rely on downloaded Python (until it also builds in the same environment). Somehow the Qt build process uses Python at some point. If you contact me I can share my preliminary work for Qt. – Brecht Sanders Jun 13 '20 at 07:00
  • I have added some details above on how I build OpenSSL (both static and shared), in case you are still stuck on that. – Brecht Sanders Jun 20 '20 at 20:23