Building Qt5 on Windows

This page will explain how to compile Qt libraries on Windows 32bit environment with WebKit module, OpenSSL support and PostgreSQL support in QtSql library.

Everything is done using a Windows 7 x86 installation with an old Dell laptop with Intel T2700 Centrino CPU and 3,2 GB of RAM (2x2GB, usable only 3,2GB).

My compiler is mingw-w64. You must use this variant of mingw because it has a better support in include files which can break the compilation system of Qt 5 libraries.
Don’t worry about the name. You can install minngw-w64 with binaries built to running in a 32bit environment that produce 32bit binaries. You can download it using the installer.
I’m using the one with GCC 4.9.1, POSIX threads and dwarf exception handling.
In MinGW environments, the Make command is called “mingw32-make.exe”, but OpenSSL building system expect it to be “make”. To proper compile this library and for a simple invocation, especially in BASH environment, you have to create a copy of the file “mingw32-make.exe” in “make.exe”. Put the copy inside the same directory (/bin folder of MinGW).

You will also need a MSYS environment and a working Perl installation.
MSYS can be installed using the standard MinGW installer and choosing to install only “msys-base” package.
After that you can download and install Strawberry Perl, a full Open Source Perl build for Windows. Remember to choose to automatically add definitions in system %PATH% variable.

Some packages can be configured using CMake. Since CMake for Windows contains a GUI which make configurations simple, you can download and install CMake using the official installer.

Some building processes need an Assember. You may choose to install NASM. Just download a Windows build and copy both nasm.exe and ndisasm.exe into mingw-w64 “/bin” directory.

Qt libraries use python (version 2) during build process. Download and install Python interpreter using the official installer.

You may need an advanced text editor just-in-case of problems. Install Notepad++.

I used these source archives:

Step 1: building zLib

zLib can be configured using cmake.
Open a MinGW terminal, move to zLib unzipped sources directory and run “cmake-gui”.

Choose a proper installation prefix and remember to deselect ASM686 to disable Assembly. Now simply run “mingw32-make” in the previousMinGW terminal and “mingw32-make install” command to copy compiled files into installation prefix.

Step 2: building OpenSSL

OpenSSL must be compiled using a MSYS environment.
Launch msys.bat from a MinGW terminal in order to import environment configuration for gcc.
Untar OpenSSL, run the Configure script, launch the building process and install compiled file:

GCC default behavior for “-l” switch is to search for libraries with the name starting with “lib” (-lfoo search files called libfoo.dll). Some compilation processes links against -lssleay32. To ensure that gcc is able to find OpenSSL libraries remember to create a copy of the library “ssleay32.dll” located in the /bin folder with the new name of “libssleay32.dll”.

Step 3: building PostgreSQL

As OpenSSL, PostgreSQL must be compiled using a MSYS environment. We also need to define some compiling and linking flags in order to let PostgreSQL configure script recognize all dependencies.
Prepare an BASH Script with this lines:

As you can see we define include and lib directory in compiler flags. GCC is able to find libraries using only Windows-style paths (The ones starting with “-LC:\build”). To be sure that some flags-parsing process in configure script is able to find libraries you can also add also absolute UNIX paths (The ones starting with “-l/c/build”).

Launch PostgreSQL configuration. Remember to escape backslashes because we are in a BASH environment:

You need to manual edit “src/” in order to add linking flags. Find the two lines starting with DLLWRAP and LIBS, and add these definitions:

We need only client library, so enter in “src/interfaces” directory, compile the library and install it:

Step 4: Building Qt

Once every dependence library is done, just run configure script with correct parameters:

All options have to be written in a single line. I split every parameter to simplify reading the command line.

Now compile Qt libraries. It can take a long time to complete (about several hours). You can use parallel building using the “-j” switch to speedup the process.

You may encounter several problems.

During qtimageformats compiling you may have an error regarding libwebp support.
Qt compilation system prepare a big list which contains relative paths to all libwebp object files. This list is used directly in linking process to tell g++ which “*.o” files must be linked together in order to produce the DLL library.
During my building, g++ was unable to find listed files. I was able to resolve this problem just opening “object_script.qwebp.Release” with a text editor and “find & replace” all “./.obj” with “.obj” relative path, removing the “./” at the beginning of every line.

During qtquick1 compiling there could be an error including an header file named “qdeclarativedebugserverconnection_p.h”. Just open the file located in “qtquick1/include/QtDeclarative/5.3.2/QtDeclarative/private/” and remove a “../” in the relative include path.

At the end, just install Qt libraries:

Now you have a working version of Qt libraries built on Windows.

Una risposta a “Building Qt5 on Windows”

  1. “find & replace” all “./.obj” with “.obj” relative path, removing the “./” at the beginning of every line

    This saved me a lot of time. Thank you.

I commenti sono chiusi