Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt5 How to build Windows 32bit MinGW Static and adding MSYS tutorials



  • Prequisits are QT5 source, QT5 MinGW installed to c:\Qt. It's important to know that I banged my head with current mingw separate compiler that does use Dfarf 2 and 3 but Qt5 uses version 4 so you must use QT5 mingw to build satic lib.

    NOTE: The Source and static build takes atleast 40gb space while compiling and more until it cleans everything. Remember to use harddrive that has lot of space available for the source. The source does not need to be in C:. You can put it any drive and make it install the final build to c: to avoid any huge space taking at C:.

    The steps are:

    1. Download Source http://qt-project.org/downloads as zipped or 7-zipped. Copy source folder to C:.

    2. Append these lines to "c:\qt-everywhere...\qtbase\mkspecs\win32-g++\qmake.conf":
      @# [QT-STATIC-PATCH]
      QMAKE_LFLAGS += -static -static-libgcc
      QMAKE_CFLAGS_RELEASE -= -O2
      QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer
      DEFINES += QT_STATIC_BUILD
      @

    Open cmd, navigate to c:\qt5-everywhere and type these commands:

    1. Type enverimetal variable:
      @set path=C:\Qt\Qt5.2.1\Tools\mingw48_32\bin;C:\Qt\Qt5.2.1\Tools\mingw48_32\opt\bin;$env:SystemRoot\system32;$env:SystemRoot@

    2. Force English locale to avoid weird effects of tools localization.
      @set LANG="en"@

    5.Set environment variable QT_INSTALL_PREFIX. Documentation says it should be used by configure as prefix but this does not seem to work. So, we will also specify -prefix option in configure.
    @ set QT_INSTALL_PREFIX=C:\Qt\Qt5.2.1static@

    When updating versions then just change the numbering on the install prefixes. You can add your own Install path everywhere on your system.

    1. Then we start configure with command:
      @configure.bat -static -debug-and-release -platform win32-g++ -prefix c:\Qt\Qt5.2.1static -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests@

    These lines are copied from orginal QT5 powershell script and since the script did not work for me so I decided to use copy paste method. If you want more libs to be combiled please refer QT configure options at: http://qt-project.org/doc/qt-5/configure-options.html.

    The -prefix c:\Qt\Qt5.2.1static needs to be updated when defining another install path: This is added here because the install path enviromental variable does not always work.

    1. Compiling time:
      @mingw32-make -k -j4@

    2. Finally installing build to defined path earlier in configure:
      @ mingw32-make -k install@

    Ok I have build sucesfully and provide this build as 7-zip file here later stay tuned.

    Adding MSYS to QT environment:

    Prequisits: Install MSYS to Qt/qt*/tools/mingw*/

    2 Steps needed:

    1: Edit /etc/profile and add these to export functions:
    @if [ $MSYSTEM == MINGW32 ]; then
    export PATH=".:/usr/local/bin:/bin:/C/Qt/Qt5.2.1/Tools/mingw48_32/bin:/c/Qt/Qt5.2.1/5.2.1/mingw48_32/include":C:/Qt/Qt5.2.1/5.2.1/mingw48_32/bin:C:/Qt/Qt5.2.1/5.2.1/mingw48_32/include:$PATH"
    else
    export PATH=".:/usr/local/bin:/bin:/C/Qt/Qt5.2.1/Tools/mingw48_32/bin:/c/Qt/Qt5.2.1/5.2.1/mingw48_32/include":C:/Qt/Qt5.2.1/5.2.1/mingw48_32/bin:C:/Qt/Qt5.2.1/5.2.1/mingw48_32/include:$PATH"
    fi@

    1. Edit ffstap example and put these:
      @#Win32_Path Mount_Point
      c:/Qt/Qt5.2.1/Tools/mingw48_32 /mingw
      c:/Qt /Qt@

    Now you can compile your app with unix style methots and use autotools and what so ever. You just download unix sourcecode for the apps and use make make install method to build your libraries and then you can use those in your QT project.


  • Lifetime Qt Champion

    Hi,

    You should consider make this a wiki article, the forum threads tends to get forgotten as times passes by.

    Happy coding !



  • Hello could you help me a bit, Qt creator says invalid kit when adding qmake.exe for static lib. Where did I do wrong? I made mingw32-make instead of that powerscript mingw32-make -k -j4, does these affect somehow on the qmake version info?

    I looked mingw32-make --help and it says -k is keep going anf -j4 makes 4 jobs in same time for multitasking so I think it should not make any differences when using normal make. So how come QTCreator complains version and I cannot build anything?


  • Lifetime Qt Champion

    You might have an incomplete build. -k means that it will try to go as far as possible so you might have had a build failure somewhere and didn't notice it.


Log in to reply