Qmake - Independent executable

3

How do I compile a Qt Creator program (.pro) with "static link"? I compiled it for QT Creator, but I need to copy about 6 dlls into the executable folder, some of them are over 100mb. I read the documentation , but I did not quite understand how it does. I also saw some questions here in the OS, but none clarified well.

    
asked by anonymous 25.12.2014 / 03:02

2 answers

1

The dlls are large because you should be using the debugging ones, which are even bigger. Release releases are much smaller.

To use static linking in Qt you must have a business license. Otherwise, you can break the LGPL3 or LGPL2 license of the open version of Qt.

In Qt (I think since 5.2) there is a tool to automatically copy all the dlls and files that a Qt for Windows program needs, windeployqt .

To use it, open cmd and then the qtenv2.bat file that is inside the folder where Qt for Windows is installed.

Then, just call the program, informing the path to exe file generated by Qt. Example:

 windeployqt C:/foo/bat/programa_release/programa.exe

In this example, the files it copied are in the output:

Adding Qt5Svg for qsvgicon.dll
Direct dependencies: Qt5Core Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Updating icuin53.dll.
Updating icuuc53.dll.
Updating icudt53.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libgcc_s_dw2-1.dll.
Updating libstdc++-6.dll.
Updating libwinpthread-1.dll.
Creating directory iconengines.
Updating qsvgicon.dll.
Creating directory imageformats.
Updating qdds.dll.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjp2.dll.
Updating qjpeg.dll.
Updating qmng.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory platforms.
Updating qwindows.dll.
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_fi.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

And really, it's no small thing. There are almost 50 Mb of files. Being that QtCore + QtGui alone amount to almost 10 Mb.

    
25.12.2014 / 13:58
1

Customizing the ICU

DLLs from the ICU are actually heavy, especially with icudt5*.dll

But there is a way to customize this DLL using the ICU Data Library Customizer , so you can greatly reduce your size, as quoted in the Qt forum

Reduced examples:

Using Dependency Walker

One feature you can use to detect the required DLLs in your project is the Dependency Walker , it will help you to detect only the required dlls, using:

  • Most important of all is that you should rename the /Qt/QtX.X.X folder to something like /Qt/QtX.X.X-tmp , as some DLLs may be "registered"
  • Initially the folder with its EXE should not have any DLL except the Qt5Core and the Qt5Gui
  • Open depends.exe
  • Drag and drop the compiled application (in Release mode) of your project into the Depency Walker window
  • Copy DLLs that usually appear in yellow in depends.exe (some are not absent, may be some error, such as an x64 DLLs in an x86 project)
  • Note that in Windows you need to copy a folder that is inside the "/ Qt / plugins" folder called platforms and only one DLL is required (I believe), qwindows.dll

    Getting something like (MingW):

    ./platforms/qwindows.dll (1mb)
    ./icudt53.dll (21mb)
    ./icuin53.dll (3mb)
    ./icuuc53.dll (2mb)
    ./libgcc_s_dw2-1.dll (118kb)
    ./libstdc++-6.dll (1mb)
    ./libwinpthread-1.dll (48kb)
    ./Qt5Core.dll (4mb)
    ./Qt5Gui.dll (5mb)
    ./Qt5Widgets.dll (6mb)
    ./app.exe
    

    Disabling features

    You can disable some features , such as OpenGL and ICU in Qt by setting the flag -no-icu and -no-opengl , to do this it is necessary to use configure.exe , follow the link How to compile the static version of Qt for Windows with GCC (this link provides guidance on how to use configure.exe to configure the desired options)

    Other options you can try

    • -no-accessibility Does not compile accessibility "Windows Active Accessibility"
    • -no-stl Does not compile STL.
    • -no-sql-<driver> Disables SQL entirely
    • -no-system-proxies Disables system proxies

    Using .LIB instead of .DLL

    As colleague @Maniero said in this answer , maybe using .lib might favor release end of the project

    Do not limit yourself to Qt

    There are other "SDKs" that are cross-platform , a good example is GTK +

    A quick test-case (note that I compiled in C , used GCC , but you can compile in C++ using G++ )

    • main.c

      #include <gtk/gtk.h>
      
      int main (int argc, char *argv[])
      {
        GtkWidget *window;
      
        gtk_init (&argc, &argv);
      
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), "Window");
        g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
        gtk_widget_show(window);
        gtk_main();
      
        return 0;
      }
      

    To compile the command:

    gcc -o app.exe *.c 'pkg-config --cflags --libs gtk+-3.0'
    

    The only required DLL was zlib1.dll , the result was 131kb:

    ./app.exe (48kb)
    ./zlib1.dll (83kb)
    
        
    25.12.2014 / 04:31