Donald Duck Donald Duck - 1 month ago 17
C++ Question

Statically linked application - size reduction

I had a

300 KB
application linked dynamically, due to plenty of issues I decided to try static linking build.

I configured Qt with the following:

configure -c++11 -mp -static -debug-and-release -platform win32-msvc2012 -opengl desktop -opensource -confirm-license -make libs -nomake tools -nomake tests -nomake examples -no-openssl -skip webkit


On the dynamically linked build I only had to link to the dependencies:

qtmain.lib
Qt5Gui.lib
Qt5Core.lib
Qt5Widgets.lib
Qt5Network.lib
Qt5WinExtras.lib
qwindows.lib


Now I have to use 15 libraries!

qtmain.lib
qtpcre.lib
Qt5Gui.lib
Qt5Core.lib
Qt5Widgets.lib
Qt5Network.lib
Qt5WinExtras.lib
opengl32.lib
imm32.lib
Ws2_32.lib
Qt5PlatformSupport.lib
qtfreetype.lib
winmm.lib
qtharfbuzzng.lib
qwindows.lib


I mean, why do I have to link against
qtpcre
, or
qtfreetype
if I'm not using regular expressions nor free type in my solution? Do I really need all of those?

I have tried to enable full optimalization.

In the results, my application size is 10,731KB and thats really frustrating and depressing. Is there any possibility to decrease it? External applications maybe?

(Yes, I am aware it's a static build and it will not be a 7MB or less file, but maybe I could get below 10MB at least?)

Shf Shf
Answer

There is a tool that significantly reduces size of executable called upx

Usage:

upx --best path/to/executable

Consider also adding -q option which would not print output). This way you can even add this tool to your build process to avoid additional manual step.

Comments