Build application linked with static Qt library in Windows

This procedure will build static Qt which takes hours; you've been warned.

  1. Add "C:\MinGW\bin" to system environment variable "Path" (if it isn't already)
  2. Open command line
  3. Go to "C:\Qt\2009.03\qt" folder (or where Qt is on your system)
  4. Enter "configure -static -platform win32-g++"
  5. Select one of the licences offered and accept whichever you want
  6. Enter "mingw32-make"
  7. Then wait for couple of hours while it rebuilds. (Take a loong lunch)
  8. Then rebuild your project again. The file size should increase by about 5-10 MB (static QT is now linked with the exe)

Solved problem 1: On Windows 7 with Cygwin installed you might get this error:


make (e=5): Access is denied.
mingw32-make: *** [project.o] Error 5
Building qmake failed, return code 2

That is because g++.exe file is probably restricted for your user. Go to C:\cygwin\bin\g++ file (or wherever you had installed Cygwin) and set access rights: Properties -> Security -> Edit -> [Your username] -> Check Full Control

Solved problem 2: Furthermore, if you're running 64 bit version of Windows with Cygwin you will receive this message:


This version of c:\cygwin\bin\g++.exe is not compatible with 
the version of Windows you're running. Check your computer's system 
information to see whether you need a x86 (32-bit) or x64 
(64-bit)version of the program, and then contact the software publisher.

And then following lines as a result of configuring Qt:


make (e=216): Error 216
mingw32-make: *** [project.o] Error 216
Building qmake failed, return code 2

The solution I found was to temporarily rename the g++.exe file in Cygwin folder so that it can't be reached for the time building Qt library, since Qt comes with it's own g++ anyway.

While you're at it, to the same for gcc also.


Previous: Qt doesn't display Jpg and Gif files in release built on Windows
Next: How to implement loop feature in libVLC play video with Qt in c++