PDA

View Full Version : Minimal size of a statically-linked Qt application



DizzyMoods
26th August 2012, 13:06
Hello.

What's the best way to reduce the size of a statically-linked Qt executable? I've configured my Qt build using:


configure -release -static -opensource -confirm-license -platform win32-g++ -nomake examples -nomake demos -no-ltcg -no-exceptions -no-accessibility -no-sql-mysql -no-sql-psql -no-sql-oci -no-sql-odbc -no-sql-tds -no-sql-db2 -no-sql-sqlite -no-sql-sqlite2 -no-sql-ibase -no-qt3support -no-opengl -no-openvg -no-gif -no-libpng -no-libpng -no-libmng -no-libtiff -no-libjpeg -no-dsp -no-vcproj -no-incredibuild-xge -no-plugin-manifests -no-plugin-manifests -no-rtti -no-mmx -no-3dnow -no-sse -no-sse2 -no-openssl -no-dbus -no-phonon -no-phonon-backend -no-multimedia -no-audio-backend -no-webkit -no-script -no-scripttools -no-declarative -no-declarative-debug -no-style-plastique -no-style-cleanlooks -no-style-motif -no-style-cde -no-style-windowsce -no-style-windowsmobile -no-style-s60 -no-mp -no-iwmmxt -no-crt -no-cetest -no-freetype -no-s60 -no-usedeffiles -no-native-gestures

This configuration basically includes all of the -no-??? directives apart from -no-stl and -no-qmake and. A simple Qt widget application still takes about 7-8 MBs. Is there any way to reduce it's size even more (besides packers like UPX)?

tbscope
26th August 2012, 14:36
I don't think you can expect a file of 1 MB.
Around 7 or 8 MB sounds about ok.

There are tools, like you mention, who can reduce the size even more by stripping out unneeded symbols and compress data.

If size is an issue, perhaps a static file is not the best solution.

d_stranz
27th August 2012, 23:27
I doubt that -any- of the -no-??? directives are actually necessary, since static linking should pull in only the dependencies you are actually using and nothing more. So if your program (and nothing that your program uses from inside Qt) is using any of the SQL drivers for example, none of the code to support them will be linked in whether you specify it on the command line or not.

It looks like most of the options you've included are intended to configure building the Qt libraries themselves, not for building applications based on Qt and would be ignored anyway.

I think you have to expect that as soon as you start including any graphical features at all (i.e. QApplication / QWidget) and statically link to Qt, the size of your executable will be much bigger than a console-only app based on QCoreApplication.