Skip to content

Compile Qt 64 bit with OpenSSL using MinGW

Christian edited this page May 29, 2018 · 28 revisions

This is how we compile Qt and OpenSSL from source. We use a minty fresh Windows 8.1 in a virtual machine. The only way to compile OpenSSL on Windows that I found is using MSYS2. MSYS2 has a nice package manager so we also use this to build Qt. Download latest 64 bit msys2 package from https://sourceforge.net/projects/msys2/files/Base/x86_64/ and install it to C:\msys64. Start MSYS2 mingw64 from the start menu.

Version Compability.

In it's jump to OpenSSL 1.1.0, there were a lot of changes to OpenSSL which are not compatible to Qt below 5.9 (at time of writing this, support for OpenSSL 1.1.0 was discussed for the future version Qt 5.9). So if you compile Qt 5.8 or lower, get an OpenSSL version 1.0.x.

OpenSSL

First we update package database and install some packages that we will need:

pacman -Sy
pacman -Syuu (Repeat until it says no more packages can be updated. You might need to restart MSYS2.)
pacman -S perl mingw-w64-x86_64-gcc make tar
pacman -Syuu (Update the packages)

Now everything is set up for the build. Download the opensSSL sources from https://www.openssl.org/source/ (or install git and check out the lastest version). Next we will untar the sources, and build openSSL. I did this in /home/buildbot/ (the user on the mashine is called buildbot).

tar xvfz openSSL-sources.xxxx.tar.gz
cd openSSL-xxxx
mkdir dist
./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw64
make depend && make && make install

OpenSSL is now compiled and installed in the previously created dist/ folder. We will now use this to compile Qt.

Build Qt in the windows command line

We will build in the normal windows command line an NOT with msys2. This way, the paths in qmake will be set correctly for use with other tools like qtcreator and qindeployqt. However, we will still use msys2 to get the needed tools:

pacman -S mingw-w64-x86_64-make python2

Now you must add the paths to the mingw compiler and to the other tools that we installed. Add the paths C:\msys64\mingw64\bin and C:\msys64\usr\bin to the windows PATH environment variable. Then, get the sources of Qt from https://www.qt.io/download/ or check them out using git. If you use the installer, we really only need the sources of Qt (and possibly Qt Charts and Qt Data Visualization). Then create a new folder (maybe named "Qt5.x-release" and cd to it. We will create a shadow build in this folder in release mode. If you also want the debug versions, just create another debug folder and configure Qt in debug mode. Next, configure Qt to build in this new folder. This line is so long because we skip a lot of the packages that we don't use in YUView. This will speed up compilation significantly. Just re-activate whatever you also might need.

C:\Qt\5.8\Src\configure.bat -release -opensource -opengl desktop -platform win32-g++ -openssl -IC:\msys64\home\buildbot\openssl-1.0.2k\dist\include -LC:\msys64\home\buildbot\openssl-1.0.2k\dist\lib -nomake examples -nomake tests -no-direct2d -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns

Qt is now conficured with openSSL. Install some more packages and use it to compile Qt.

mingw32-make (use the -j option to use multiple cores)

If you also want to build a debug version, create a new folder (maybe 5.8-debug) and cd there. The following will configure Qt to build. The difference to the one above is, that we don't build the qttools in debug mode:

C:\Qt\5.8\Src\configure.bat -debug -opensource -opengl desktop -platform win32-g++ -openssl -IC:\msys64\home\buildbot\openssl-1.0.2k\dist\include -LC:\msys64\home\buildbot\openssl-1.0.2k\dist\lib -nomake examples -nomake tests -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns

Notes

  • If configure seems to do nothing try to delete the configure.cache first. The configure.log can give valuable insight into possible errors.
  • This will compile Qt without direct 2D. If you want to try activating direct2D, just remove the no-direct2d keyword. If compilation fails, you may try to add the fpermissive flag to the QMAKE_CXXFLAGS in the qmake.conf file at Qt/5.8/Src/qtbase/mkspecs/win32-g++.
  • If you get the error that vcredistributable could not be installed, you can ignore this. Because QtCreator comes with precompiled Qt libraries that link against the vcredistributables, you will not be able to use the version of Qtcreator that ships with Qt. You can either install all windows updates for windows 8.1 in order to install the redistributable package and then run the creator (this takes a lot of HDD space), or you can just download an older version of QtCreator. I downloaded QtCreator 4.2 from heise.de.