Reduce Qt libraries size
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.
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
gccin a release build but my guess would be
O2. You can check the generated
Makefilefor the specific flags. Then you can do some digging in the documentation of
gccand see what else you can add to make the
sos smaller. Usually optimization level
Osdoes a pretty good job. I have a shared library which, when built without this level of optimization, is approx. 3MB. After setting the
Osit shrunk down to 51KB. Use
QMAKE_CXXFLAGS += ...inside your project file to specify the flags you want to pass to
gccand 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.
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.
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
-O0will be used (I actually do believe that this is the default behavour in Qt) while
-Oswill be for the release buid.
If you are more comfortable directly working with the
Makefileyou can open the generated by
Makefileand set the flag directly there however I would advice doing that just for a small check since whenever
Rebuildis executed in your Qt Creator the
Makefilewill 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
-Osflag in specific but then again it really depends on what you are doing and how you are coding it. :P