PDA

View Full Version : lightweight static linking qt?



gfunk
2nd April 2007, 22:39
So I statically linked Qt to my simple app that sends a few messages over sockets then shuts down. But the resulting executable is 850KB!! (release build, no symbols) I was wondering if there might be any compiler or preprocessor options to recompile Qt, to try to cut the executable size down to below 500kb, make it a little more lightweight. I am only linking in QtCore.lib and QtNetwork.lib.

Methedrine
2nd April 2007, 23:07
I guess you could always try to recompile Qt with size-optimization (as opposed to speed-optimization). But yeah, that would be a lot to do compared to setting a define. Sorry I know none :) Maybe looking through the Qt sources will reveal something? :-)

gfunk
2nd April 2007, 23:16
Well I snooped around in src\corelib\global and found qconfig-large.h, qconfig-medium.h, qconfig-small.h, qconfig-minimal.h, as well as a file qfeatures.h. I guess I'm just wondering if including these macros are sufficient to shrink my executable, or if I need to recompile the Qt libs, or what the recommended way of doing this is.

gfunk
2nd April 2007, 23:29
so I included qconfig-minimal.h and got rid of some of the compile errors by undefining
QT_NO_TEXTSTREAM and QT_NO_SETTINGS. But I got no change in executable size. Maybe VC already does a good job of truncating the unused functions. I note that QtCore.lib is 14MB and QtNetwork about 1.4MB, so maybe I should just be happy that it's less than 1MB and hope no one notices. :p

Brandybuck
2nd April 2007, 23:37
Under Unix and Mac, you can "strip" a statically linked binary. I don't know if your "release, no symbols" is the equivalent.

Qt/Embedded (qtopia) has build options to define out unwanted parts of the library. These defines are in the Qt source code, so you can use them. But the Qt configure script doesn't support them, so you will have to hack a bit on the project files to get a minimal build.

wysota
3rd April 2007, 09:01
You can also pack the resulting binary with solutions like UPX (http://upx.sourceforge.net/). Stripping down things like STL support, rtti, exceptions from Qt may also reduce the binary size.

gri
3rd April 2007, 15:40
With the msvc compiler you can also enable function level linking and remove unused symbols/functions from the code.

Compiler flags + "/Gy"
Linker flags + "/OPT:ICF /OPT:REF"

If not already done :)

jamadagni
16th April 2007, 04:20
With the msvc compiler you can also enable function level linking and remove unused symbols/functions from the code.
Compiler flags + "/Gy"
Linker flags + "/OPT:ICF /OPT:REF"
If not already done :)
The same can be done while using gcc by passing the options


-fdata-sections -ffunction-sections -Wl,--gc-sections

The last one is actually an option --gc-sections to the linker ld, but gcc passes that on when we prefix it by -Wl,