Static linking of Qt 5.xx with MinGW32 on Windows (assembly in one exe ')

Good day, Khabrav residents!



I'm sure everyone noticed when they deployed their program via windeployqt.exe, the program depends on different dynamic and qt libraries. As a result, scanning on other computers becomes inconvenient. Why? You have to keep the exe's file itself in the folder with the necessary libraries. Of course, you can manage to solve this problem without static linking. Agree, it's inconvenient, and every time you need to do extra body movements. It's easier to get worn out once and then not make unnecessary movements. Another plus of static linking is the file size. With dynamic linking, the exe itself weighs from about 1 MB to 7-8 MB, and with the environment it can easily reach 70 MB, even if the project is small. With static linking, there is only an exe, which weighs about 2 times less than the environment with dynamic linking.



For assembly you need:



  • Qt 5.xx with components enabled (if Qt was already installed, the required components can be installed using the Qt Maintenance Tool):

  • Qt - Qt 5.x - MinGW xxx 32 bit

  • Qt - Qt 5.x - Sources

  • Qt - Tools - MinGW

  • Perl (Strawberry Perl, for example). I am using strawberry-perl-5.30.2.1-32bit.

    Check that the path to the Perl executable file is registered in the PATH environment variable. You can skip this point, but it's better to check.
  • Python 3.8



The installation path of Qt is not important, I have it installed on drive D. Make sure you have enough available memory. You need at least 30 GB of free space.



The algorithm itself:



  1. Go to the directory where the Src folder (D: \ Qt \ 5.xx \ Src);
  2. There, create a static folder (D: \ Qt \ 5.x.x \ static);
  3. Src static. D:\Qt\5.x.x\static\Src. , Src;
  4. mingwXX_32 ( , , mingw73_32). D:\Qt\5.x.x\static\mingwXX_32;
  5. qmake.conf, D:\Qt\5..\static\Src\qtbase\mkspecs\win32-g++.



    , load(qt_config)



    :



    QMAKE_LFLAGS += -static -static-libgcc
    	   QMAKE_CFLAGS_RELEASE -= O2
               DEFINES += UNICODE QT_STATIC_BUILD
          
          





  6. qmake.conf;
  7. (! CMD! CMD! CMD!) MinGW. ( ) mingw.

    MinGW Qt 5.x.x (MinGW x.x.x 32-bit)

  8. MinGW :

    set LANG=en







    set QT_INSTALL_PREFIX="C:\Qt\5.8-static\mingw53_32"
          
          





    cd /d %QT_INSTALL_PREFIX%\..\Src







    ( )



    configure.bat -static -debug-and-release -platform win32-g++ -prefix %QT_INSTALL_PREFIX% -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -qt-sqlite -no-ssl
          
          





    -no-ssl β€” Qt SSL.



    , :

  9. mingw32-make -k -j4





    , 4 , / , . -j4 4 .

  10. mingw32-make -k install





    D:\Qt\5.x.x\stati\mingwXX_32;

  11. Qt Creator:

    • -> -> Qt
    • -> D:\Qt\5..\static\mingw73_32\bin\qmake.exe ->
    • ->
    • : Qt static x32 ( )
    • : Desktop
    • :
    • : D:\Qt\5..\static
    • Compiler:

      a) for C: MinGW xxx 32-bit for C

      b) for C ++: MinGW xxx 32-bit for C ++

    • Qt profile: Qt static x32 (the profile name you provided when adding the profile)
    • Apply -> Ok


  12. All that remains is to rebuild your project with a new kit.


Additional Information. I have:



  • Qt 5.14.1
  • MinGW 7.3.0 32-bit (mingw73_32)
  • Python 3.8 x32
  • strawberry-perl-5.30.2.1-32bi
  • Windows 10 Pro x64


The flight is normal.



I took information from here:






All Articles