Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minimize the size of Qt applications?

Tags:

qt

The size of application with all needed .dll files is very big (almost 30 mb). How I can reduce this size?

like image 743
iVi Avatar asked Jul 01 '14 14:07

iVi


Video Answer


2 Answers

In theory, you can do any of the following:

  1. Disable the Qt features you don't use. See the official documentation on the subject.
  2. Use an older Qt version, which has less dependencies on e.g. ICU and less libraries in total.
  3. Build everything with link-time optimizations, including the Qt DLLs. Your mileage may vary (you might even get bigger, but faster in the process).
  4. Build everything statically, and link only what you need. Note that this strongly depends on the capability of the linker and compiler to eliminate dead code. This may or may not prove worthwhile: usually, most of a DLL's contents are used, so you may only shave off a MB or so. Some compilers (notably MSVC) cannot cope with the object file size this results in (maybe only when combined with #2).
  5. Don't care: we live in the age of broadband internet. Compress your distributed package with e.g. 7z to minimize download time.
  6. Compress your binaries with something like UPX. Will partially mitigate #4.

I'd just go with 4.

like image 185
rubenvb Avatar answered Sep 19 '22 06:09

rubenvb


Other than the generic principles (strip the binary, do not use QML if you are happy with C++, etc), I think you need to use configure for this to disable the features you do not need:

Including or Excluding Features

The -feature- and -no-feature- options include and exclude specific features, respectively, where is listed in the file qtbase/src/corelib/global/qfeatures.txt. For example, to disable Accessibility, provide -no-feature-accessibility as the argument:

./configure -no-feature-accessibility

Disclaimer: you are in your own territory with this, so you may end up having lots of issues that you need to fix up.

like image 21
lpapp Avatar answered Sep 20 '22 06:09

lpapp