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





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

  1. 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.

  2. 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.

Leave a Reply

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