How to Build Qt 5.9.2 Static Using MinGW

You can follow the instructions below to build Qt 5.9.2 from sources using MinGW, and statically. To be able to proceed further, you need to make sure you have all the prerequisites on your PC, which are mentioned in this post, then return here.Assuming that you have taken care of all the requirements, you can start by downloading MinGW and Qt 5.9.2 source codes, or take the better and “recommended” route and simply download both of them using the Qt 5.9.2 all-in-one installer for Windows.



Here’s the link:

https://download.qt.io/official_releases/qt/5.9/5.9.2/qt-opensource-windows-x86-5.9.2.exe

When you run the installer just make sure to check the compiler and source codes checkboxes as seen here:

Assuming that you have installed Qt into the default path, you have to make sure the following two entries are added to the PATH environment variable:

C:\Qt\Qt5.9.2\5.9.2\Src\gnuwin32\bin
C:\Qt\Qt5.9.2\Tools\mingw530_32\bin

Then create the following folder:

C:\Qt\Qt5.9.2\5.9.2\mingw53_32_static


Now start a command prompt instance and run the following command in “C:\Qt\Qt5.9.2\5.9.2\Src” folder:

configure -opensource -confirm-license -static -platform win32-g++ -opengl desktop -prefix "C:\Qt\Qt5.9.2\5.9.2\mingw53_32_static" -skip webengine

Note that WebEngine module can’t be built statically so it is skipped. Also you can skip building tests and examples for a shorter build time, in that case you have to use the following command instead of the one above:

configure -opensource -confirm-license -static -platform win32-g++ -opengl desktop -prefix "C:\Qt\Qt5.9.2\5.9.2\mingw53_32_static" -skip webengine -nomake tests -nomake examples

After that, run this command (this will take a long time, and will require a lot of disk space):

mingw32-make

And finally this:

mingw32-make install

After the install process you’ll get your static build inside the following folder:

C:\Qt\Qt5.9.2\5.9.2\mingw53_32_static

You can also run the following command to get rid of build files you don’t need (since the install command already copied them to your static build destination folder):

mingw32-make clean


25 Replies to “How to Build Qt 5.9.2 Static Using MinGW”

  1. I found I had to use the following configure to get it to work for me:

    configure.bat -release -static -static-runtime -no-pch -optimize-size -opengl desktop -platform win32-g++ -prefix “C:QtQt5.14.25.14.2mingw73_64-static” -skip webengine -nomake tools -nomake tests -nomake examples -qt-zlib -qt-libjpeg -qt-libpng -qt-freetype -qt-pcre -qt-harfbuzz -qt-tiff

    check the prefix value before you hit enter.

    My notes: https://docs.google.com/document/d/1rw0JxO47fFVGUvWCv9IiK4m-V9whfd8EqO4YEi1RRmI/edit?usp=sharing

  2. hi , amin i am getting “mingw32-make is not a recognized internal or external command”

    do you know where i went wrong?
    by the way i am compiling 5.11.2

    thanks man

  3. Hi, thanks for this guide!), but how about MSVCx64 static link. build??. Can you make guide about this?

    1. Good point, you can set the number of jobs using the “-j” or “–jobs” parameter.
      Here’s how:
      -j [N], –jobs[=N] (Allow N jobs at once; infinite jobs with no arg.)

      Although 8 or any other number, it totally depends on your computer specifications.

  4. Yes it acually did: but the command mingw32-make ended with errors:
    lib\libqtpcre2d.a
    mingw32-make[5]: Leaving directory ‘C:/Qt/5.10.1/Src/qtbase/examples/network/download’
    mingw32-make[5]: write error: stdout
    Makefile:36: recipe for target ‘debug’ failed
    mingw32-make[4]: *** [debug] Error 1
    mingw32-make[4]: Leaving directory ‘C:/Qt/5.10.1/Src/qtbase/examples/network/download’
    Makefile:56: recipe for target ‘sub-download-make_first’ failed
    mingw32-make[3]: *** [sub-download-make_first] Error 2
    mingw32-make[3]: Leaving directory ‘C:/Qt/5.10.1/Src/qtbase/examples/network’
    Makefile:177: recipe for target ‘sub-network-make_first’ failed
    mingw32-make[2]: *** [sub-network-make_first] Error 2
    mingw32-make[2]: Leaving directory ‘C:/Qt/5.10.1/Src/qtbase/examples’
    Makefile:69: recipe for target ‘sub-examples-make_first’ failed
    mingw32-make[1]: *** [sub-examples-make_first] Error 2
    mingw32-make[1]: Leaving directory ‘C:/Qt/5.10.1/Src/qtbase’
    Makefile:78: recipe for target ‘module-qtbase-make_first’ failed
    mingw32-make: *** [module-qtbase-make_first] Error 2

    Does this influence the working of QT or not ??

    1. Hmmm, well this looks like building some example projects have failed. So, the best way to make sure everything is OK is to try it. But my guess is that you’ll be alright.

      1. Thanx mate,
        the install is complete, but it took huge space on my HD (around 90GB)
        is there by chance a way to build QT dynamically?? or what can i sip from installation to use less space?

        1. Omit -static and you’ll get the dynamic libraries. Other than that you can use -nomake examples and similar commands to skip the things you’ll (most probably) won’t need.

          1. Yeah that’s good option. but after the installation finished, i tried a plain app c++ with hello world code and qapplication headers, it gave me errors like: qapplication header not found. is there other steps to do after your tutorial ??

  5. Hello for simplifiions much these steps. I did them all correct except the third one, I didn’t change the src path as it’s different on my machine.but I repeated it after it finished with the correct path, then I continued the next steps. For now it’s taking much time on the 4th step, I wanna know if it would be installed in the correct folder or I should cancel and repeat all the steps??

  6. Hi amin , thanks for the tips , this post is way more helpful than qt notes
    i just have one question
    “this will take a long time, and will require a lot of disk space”
    how much time and how many space exactly?
    the damn thing is making like 8 hours for me and took around 150 GB up until now
    i have encounter low disk space 3 times , i uninstalled a lot of my programs and remake again . my C drive has 200 GB completely ,lets say 170 GB at best free , is this enough ?
    damet garm , vaghean gir bodam sare in

    1. Hi Saeed,
      Unfortunately I don’t have an estimate, but just to confirm that you are on the right path, yes it needs a lot of space as you have experienced already.
      However, and as stated in the tutorial, make sure to include “-nomake tests -nomake examples” options to speed things up.
      On another note, do you have to use MinGW? You’ll need less time and space with MSVC compilers.
      Hope this helps.

      1. thank you amin
        i did it without the examples and tests and it was way faster and smaller , installed the qt static and made a kit out of it .
        i’m just having 2 difficulties
        first i could not find the path to cmake , in your tutorial CMake in kit in the combo box you selected the cmake , i don’t have and don’t have nmake too , are they necessary(i was working without a cmake in dynamic) ?
        second ,even without a cmake i was able to get the exe file , but the size , its just very huge . i just have a button and in click-slot there is a Qmessagebox with “Hello” text on it , and the final exe file is about 380 MB ,is it normal ? I was expecting more like 1 MB size.
        if it is normal is there any way to compress it somehow?
        thank you again for all of your tips

        1. First off, you don’t need cmake, not necessarily. You can use qmake which I assume is being used by default for you that is why you get your exe without any issues. The size will decrease if you choose Release mode when building, however it will still be a lot bigger than one MB. The reason is simply because you are using static libs and the necessary Qt codes are kind of copied into your executable instead of being provided in a DLL file. Google for the difference between dynamic and static linking and you’ll find the answer.

  7. Hi! I followed your tutorial and at the end I don’t now how to add the new Compiler in Qt. Which file I need to choose, because I don’t have g++ in the static folder. Thanks !

    1. Did you make sure to check MinGW 5.3.0 during installation? The compiler should be added automatically,
      If you used the default paths, g++ should be inside C:\Qt\Qt5.9.2\Tools\mingw530_32\bin
      As it is mentioned in the tutorial, you also need to add it to the PATH environment variable.
      If you have problems adding the kit, you can see this post for some tips. The compiler is different but the logic for adding kits is the same:
      http://amin-ahmadi.com/2016/09/22/how-to-build-qt-5-7-statically-using-msvc14-microsoft-visual-studio-2015/

      Let me know if this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.