Qt TutorialsTutorials

How to Build Qt 5.9.2 Static Using MinGW

Posted

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





2 thoughts on “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.

Leave a Reply

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