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.
IL -
Hi,
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 beO2
. You can check the generatedMakefile
for the specific flags. Then you can do some digging in the documentation ofgcc
and see what else you can add to make theso
s smaller. Usually optimization levelOs
does a pretty good job. I have a shared library which, when built without this level of optimization, is approx. 3MB. After setting thegcc
to useOs
it shrunk down to 51KB. UseQMAKE_CXXFLAGS += ...
inside your project file to specify the flags you want to pass togcc
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,
IL -
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.
-
@IL
QMAKE_CXXFLAGS
(and its derivatives) is something that you put inside your project file:TARGET = BlahBlah # ... QMAKE_CXXFLAGS += -Os # ...
For example I have pri file with a bunch of stuff among which I have
QMAKE_CXXFLAGS_RELEASE += -Os QMAKE_CXXFLAGS_DEBUG += -O0
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 byqmake
Makefile
and set the flag directly there however I would advice doing that just for a small check since wheneverRebuild
is executed in your Qt Creator theMakefile
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,
Bernhard