Important: Please read the Qt Code of Conduct -

Reduce Qt libraries size

  • Hi guys,
    Is there any suitable way to reduce Qt shared objects files size using QT tool or using any other external tool, this is sure after removing all unnecessary features in configuration and striping of-course.
    I am asking that because we are limited in our disk space.
    I already search for external tools and found mklibs, this tool cut-down shared libraries to contain only the routines required by a particular set of executable, but this is seem to be fit for debian systems.

    Please advice.

  • Lifetime Qt Champion


    Are you looking for a way to build Qt with a reduced feature set to match only what you need ?

  • @IL I'm not sure about the flags that QMAKE uses when calling gcc in a release build but my guess would be O2. You can check the generated Makefile for the specific flags. Then you can do some digging in the documentation of gcc and see what else you can add to make the sos smaller. Usually optimization level Os does a pretty good job. I have a shared library which, when built without this level of optimization, is approx. 3MB. After setting the gcc to use Os it shrunk down to 51KB. Use QMAKE_CXXFLAGS += ... inside your project file to specify the flags you want to pass to gcc and test various configurations. In addition to that @SGaist gives also a great suggestion - reducing the feature set of Qt. If you know for sure which components you need then you can dispose of the rest. Some of the components (such as charts and data visualization) are actually considered extra (mostly due to licensing issues would be my guess) and when building Qt you have to explicitly configure your build to add those.

    Please provide more information on the device, your use case scenario and the current configuration you have. More details on the application you are building would also help us provide you with more advice.

  • @Red-Baron, I will take your advice for checking gcc optimization but truly I do not find a way to do so.
    Basically I am running the configuration command and then the qt-make

    ./configure -v -device arm-none-linux-gnueabi -device-option CROSS_COMPILE=$CROSS_COMPILE -release -confirm-license -opensource -nomake examples -qt-zlib -no-pch -no-largefile -no-c++11 -no-cups -lrt  -linuxfb -no-xcb -no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-accessibility -no-openssl -no-gtkstyle -xplatform devices/arm-none-linux-gnueabi --prefix=/opt/HH/CodeSourceryArm2009q1203/arm-none-linux-gnueabi/libc/usr -no-qml-debug -no-avx -no-avx2 -no-mips_dsp -no-mips_dspr2 -no-mtdev -no-libproxy -no-xkbcommon-evdev -no-xinput2 -no-xcb-xlib -no-nis -no-iconv -no-evdev -no-tslib -no-icu -no-fontconfig -no-dbus -no-use-gold-linker -no-separate-debug-info -no-directfb -no-kms -no-gcc-sysroot -no-libinput -nomake tests -gstreamer 1.0 -force-pkg-config -no-audio-backend -no-freetype -no-harfbuzz -no-qpa
    make module-qtbase

    Where should I add the O2 or OS flags?
    As I mention above regarding @SGaist recommendation about remove unnecessary features, I think I already did what I can.

    Best regards,

  • Lifetime Qt Champion

    Then you should take a look at the Qt Lite project. Short version: It's a big refactoring of the current "feature" system that allows to build Qt with less features. The Qt Lite project will offer an easier way to get that.

  • @SGaist I will check that.
    Best regards,

  • @IL QMAKE_CXXFLAGS (and its derivatives) is something that you put inside your project file:

      TARGET = BlahBlah
      # ...
      # ...

    For example I have pri file with a bunch of stuff among which I have


    which basically means that of debug build -O0 will be used (I actually do believe that this is the default behavour in Qt) while -Os will be for the release buid.

    If you are more comfortable directly working with the Makefile you can open the generated by qmake Makefile and set the flag directly there however I would advice doing that just for a small check since whenever Rebuild is executed in your Qt Creator the Makefile will be replaced with a fresh one and your changes will be gone. That is why using the project file for setting these things is the right way to go.

  • @Red-Baron That's a very interesting approach. Have you encountered any problems when using that optimization level together with the Qt framework? I am always afraid to run into some strange optimization errors. (when the debug version behaves slightly different to the release version) I know that those things occur very rarely, but when they occur they are pretty hard to detect.

    Have a nice day,

  • @Schluchti I don't recall ever having an issue with the -Os flag in specific but then again it really depends on what you are doing and how you are coding it. :P