Qmake - Independent executable

Asked

Viewed 1,327 times

3

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

  • 1

    Gabriel only debug Dlls weigh, release Dlls are much lighter

  • Still, it reaches more than 40 Mb.

  • Unfortunately yes, in most cases the size of your project will get 100mb, compressed with 7z (to create an installer) should get about 33mb. Nowadays it is difficult to have software with less than 100mb installed.

  • The problem is that it is an application with nothing, only a form(Qt) and a header(1kb). In visual studio, this would be around 4mb, with libraries.

  • Gabriel talevz has copying dll the most, please try my answer... Merry Christmas (I don’t even celebrate it rs)

  • If I understand what you call link static. You cannot do this without purchasing the commercial license. Technically it is possible but it is not legal. I think it’s an exaggeration the 100MB @Guilhermenascimento spoke about (not that it’s not possible all this size) but don’t expect a GUI application to be less than a few megabytes, linked statically or dynamically. In fact I confirm that from what I imagine you are doing, that is, very simple tests, if you are using more than 2 or 3 Dlls, I think there is something wrong.

  • @bigown I agree, I really exaggerated, is that it’s been kind of hard to see applications with less than 20mb, really it was a mistake of mine, but with QT I could not get less than 40mb (at least with Mingw). Thank you for the information on the link.

  • 1

    Any Hello World in Gui will stick with some MB. Indeed link statically can decrease the size a little (I’m talking about this in that reply, but it seems that few people understand this) but do not expect miracles mainly because Qt has many dependencies and the form of the compilation also may not help much.

  • @bigown I’m reading, I think I’m beginning to understand, I’ll study. Thank you for this reply. I edited the reply and put a reference to your link. Thanks again! Merry Christmas

  • The distribution using Qt really gets big without static linkage, but your program will work standalone, using other frameworks like . NET or the Java libraries they become small but because the user already has the libraries on his computer. You can use the UPX to try to reduce the size of the final binaries.

  • You don’t need all the Dlls, only the ones you actually use in your application. I’m finding this amount of data that you mention too exaggerated, I’ve never been able to reach even halfway with full application distribution in Qt.

Show 6 more comments

2 answers

1

Customizing the ICU

The Dlls of ICU really are heavy, mainly the icudt5*.dll

But there is a way to customize this DLL using the ICU Data Library Customizer, thus being possible to greatly reduce its size, as mentioned in qt forum

Reduced examples:

Using the Dependency Walker

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

  1. The most important thing first of all is that you should rename the folder /Qt/QtX.X.X for something like /Qt/QtX.X.X-tmp, because some Dlls may be "registered"
  2. Initially the folder with your EXE must not have any DLL except the Qt5Core and the Qt5Gui
  3. Open the depends.exe
  4. Drag and drop the compiled application (in Release mode) from your project into the "Depency Walker) window"
  5. Copy Dlls that usually appear in yellow on depends.exe (some are not absence, may be some error, such as a Dlls for x64 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 resources

You can disable some resources, like Opengl and ICU in Qt flag -no-icu and -no-opengl, to do this it is necessary to use the configure.exe, follows the link How to compile static version of Qt for Windows with GCC (this link provides guidance on how to use the configure.exe to configure the desired options)

Other options you can try

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

Using . LIB instead of . DLL

As Mr @Maniero said in this answer, maybe use .lib may favor in size release end of the project

Don’t limit yourself to Qt

There are other "Sdks" that are cross-Platform, a good example is GTK+

A quick one test-case (note that I have compiled in C, used GCC, but you can compile in C++ using the 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 DLL required was the zlib1.dll, the result was 131kb:

./app.exe (48kb)
./zlib1.dll (83kb)
  • There is no dll more, I tested manually. I started without any dll, the one that was missing, I copied to the executable folder, until the program ran.

  • Keep viewing the dlls in "yellow", usually they are missing (or present some error), if it is a dll that is not in the QT folder, maybe it is a dll from Mingw or Visualstudio that is needed.

  • No missing, no dll left.

  • @Gabrielsales Add a test-case using Mingw, unfortunately two factors prevent developing applications with low weight, the first is the QT CORE that are accompanied and made obligatory (the requires the dlls) and in my case (mingw) the DLL required call icudt53 (ICU library).

  • 1

    Qt is creating alternatives: http://doc.qt.io/qt-5/qtwebengine-index.html http://doc.qt.io/qt-5.4/qtwebview-index.html

  • @bigown Thanks for the links, I just posted that as an account, for another reason of trying alternatives, but when reading the links I could not see anything related to qtwebkit except in the case of Android iOS, as the link: http://qt-project.org/wiki/New-Features-in-Qt-5.4 Qtwebkit has been deemed ready and will be replaced in the future by the webengine. At the last "mailing" I saw, there is no information to try to support Mingw with Chromium in QT. I edited the answer, I hope it was within the "scope" of the question.

Show 1 more comment

1

As dlls are great because you should be using the debug ones, which are bigger even. The release ones are much smaller.

To use static linkage in Qt you must have a commercial license. Otherwise, you may 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 dlls and files that a Qt program for Windows needs, the windeployqt.

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

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

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

In this example, the files he 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. It’s almost 50 Mb of files. Qtcore + Qtgui alone add up to almost 10 Mb.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.