36

I'm totally new in using Qt and I don't know a lot of stuff.

As a test I created a simple application using Visual Studio 2012 and Qt-VS-Add-in based on the newest Qt5.1

After I compiled the application it didn't work for me (gave errors), I searched all over the internet and found a lot of people saying that I have to copy those dlls mentioned below from the directory:

C:\Qt\Qt5.1.0\5.1.0\msvc2012\bin\

DLL's I had to copy to make my application work:

icudt51.dll
icuin51.dll
icuuc51.dll
libEGL.dll
libGLESv2.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll

My problem is the size of these dlls, they're about "37 MB" and my application itself is only "30 KB"! So, those Qt libraries will add at least 37 MB to my application [ Which I don't see it happens with other Qt-based applications I download ]. Is there any solution can make me end up with a single small .exe file?!


And I heard some people saying that I have to also include a dll for Microsoft C++ Compiler, can you explain this for me?


Note: I've come across a lot of questions here on StackOverFlow but I couldn't find anything can help me, so please do not flag this as a duplication because if I found a clear answer I wouldn't post this question!


Any help would be appreciated.

Alaa Salah
  • 885
  • 1
  • 13
  • 23
  • I had this issue too. The ICU libraries are huge. I wonder if it's possible to recompile it so it's smaller. Also I don't use OpenGL directly in my app but I need to include EGL and GLES -- maybe recompiling Qt with some flags would help. But for now I have to stick with Qt 4.8. – hluk Jul 19 '13 at 05:30
  • 1
    If you don't need qtwebkit, you can recompile Qt without ICU support and then leave out the ICU dlls. – Frank Osterfeld Jul 19 '13 at 09:05

6 Answers6

31

UPDATE: Use windeployqt.exe! It works really well.

http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool

The simplest way to use windeployqt is to add the bin directory of your Qt installation (e.g. ) to the PATH variable and then run:

windeployqt <path-to-app-binary>

UPDATE: Upon Further testing, windeployqt did not copy over all the MingW dlls for me. (Tested with Qt 5.4 on Windows 10 with MingW 4.9.1). So you need to manually get the last 3 dlls before deploying:

libgcc_s_dw2-1.dll
libstdc++-6.dll
libwinpthread-1.dll

From

C:\Qt\5.4\mingw491_32\bin

I think you may have a few extras in your list... I would double check the docs in the links below...

Here is the definitive documentation on it:

http://doc.qt.io/qt-5/windows-deployment.html

http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies

Size of Qt DLLs

The amazing Qt Libraries can do a lot, but they are kind of big. Some of the older versions of Qt might be a little smaller.

For Qt 4.8 msvc QtCore4.dll is 2.5 MB, and QtGui4.dll is 8.4 MB.

How Windows Resolves Shared Libraries/Dynamic Link Libraries (DLL)

Here is how Windows tracks down a library at runtime:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

Single Small EXE

If you statically link, then your EXE should grab the libraries it needs and gets built into a stand alone exe. It still may be dependent on msvc redistributables. See the next section for more info on it. But it now compiles down the .libs that you reference into your EXE and your exe no longer is pointing at other dynamically linked libraries. It does take more time to get your statically linked exe environment setup.

Your exe will certainly get bigger as it now includes the binary information for the libraries that you referenced before.

https://www.google.com/search?q=qt+static+linking

EDIT: Statically building the exe, means that you aren't using the LGPL version. means that you have to have your object files easy to access to end users if you are using LGPL.

I think @peppe described it well (see comment below):

Technically, you are allowed to statically link when using Qt under LGPL, even if your application is not using LGPL. The only tricky requirement is keeping the ability for a third party to relink your application against a different Qt version. But you can comply with that easily, f.i. by providing a huge object file (.o) of your application, that only needs to be linked against any Qt version.

http://blog.qt.io/blog/2009/11/30/qt-making-the-right-licensing-decision/

Look at the chart near the bottom. If you are doing the commercial version, then you can statically link, without worrying about the object files.

MSVC Redistributables

Redistributable dependencies have to do with the run-time library linker options.

http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx

/MD, /ML, /MT, /LD (Use Run-Time Library)

To find these options in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Code Generation in the Category box. See the Use Run-Time Library drop-down box.

These two links below talk about some older versions of visual studio, but the reasoning should still stand.

http://www.davidlenihan.com/2008/01/choosing_the_correct_cc_runtim.html

How do I make a fully statically linked .exe with Visual Studio Express 2005?

Hope that helps.

Community
  • 1
  • 1
phyatt
  • 18,472
  • 5
  • 61
  • 80
  • 5
    Technically, you **are allowed to statically link when using Qt under LGPL, even if your application is not using LGPL**. The only tricky requirement is keeping *the ability for a third party to relink your application against a different Qt version*. But you can comply with that easily, f.i. by providing a huge object file (.o) of your application, that only needs to be linked against any Qt version. – peppe Jul 19 '13 at 06:46
  • True. Thanks for keeping me honest @peppe. I'll update my post to reflect that. – phyatt Jul 19 '13 at 07:04
  • Thanks for the useful informations. Right now I can't compile Qt statically, so I'm stuck with the solution I posted. – Alaa Salah Jul 24 '13 at 19:49
  • "UPDATE: Use windeployqt.exe! It works really well." - tried it yesterday, it works really, really bad. Failed to pull in dependencies, pulled a lot of unnecessary libraries. For QML files it did even worse - barely managed to do anything correctly. – dtech Feb 13 '16 at 15:09
  • @dtech Before `windeployqt.exe`, I would backup the qt plugins and dlls in my `Qt/` folder then while running my release exe, delete as many dlls as possible in the Qt folder. This would leave me with all the ones that are currently linked and in use by my exe. It was a little time consuming, but it worked. Then you take the net result of the delete and put them next to your exe and you have a bundle. I haven't tried any of it with the QML environments. – phyatt Aug 30 '21 at 20:04
9

Just open your terminal execute your_qt_installpath/version/compiler/bin/windeployqt.exe YourApplication.exe. It will automatically copy all the required libs and stuff into the folder, where your exe is located and you can just distribute it.

Niklas
  • 23,674
  • 33
  • 131
  • 170
1

For Windows you need to include qminimal.dll and qwindows.dll, you will have to put them in folder called platforms.

Even if you program is small you still call huge libraries to do the graphical interface. If the size is really important you should do a console project.

PS : You can check all the libraries you really need by opening your exe with the dependency walker.

R.Falque
  • 904
  • 8
  • 29
1

I found another workaround without recompiling Qt again!

[ This solution may affect application execution time ]

  • First we need to use UPX to compress each one of Qt Libraries required by our application, they're often the dll's mentioned in the question. However, avoid compressing them too much because you'll notice that your application takes longer time to run.
  • [ Optional ]: If your application binary is large, you may find it useful to compress it using UPX.
  • After compressing all binaries, we want to get a single .exe file, so we can use

    Enigma Virtual Box [ http://enigmaprotector.com/en/downloads.html ] to merge all .dll files with the main executable and we'll end up with a single tiny .exe file!

I'll just do it like this for now since I'm not able to recompile Qt with my own configurations on my current machine.

Alaa Salah
  • 885
  • 1
  • 13
  • 23
1

it looks to me that Qt5.2 requires fewer dll.

Qt5Core.dll 
Qt5Gui.dll 
Qt5Widgets.dll

in windows you also need "qwindows.dll" in folder "platforms". give it a try.

Fay100
  • 175
  • 1
  • 9
1

A possibility for reducing the size of the DLLs is by compressing them with UPX as mentioned by Alaa Alrufaie. Another method is to wrap it into an installer (e.g. Inno Setup). The latter one is particularly useful if you want to distribute it to end users). I had a simple application requiring Qt5Core.dll, Qt5Gui.dll, Qt5Widgets.dll and qwindows.dll (in the folder "platforms") taking about 17 MB. After creating a setup file, it shrank to 5 MB.

Zoltán Csáti
  • 679
  • 5
  • 17
  • 1
    Compression is not a solution to leanness. Qt is a massive library and the best solution is to link as little of its code as possible into your application, not attempt to save HDD space by compressing the file. It will in fact decompress during runtime and negatively impact performance of the program. – bryc Jul 29 '20 at 16:20