Building optimized Qt4 - .. / configure flags and their values

I recently went on to discuss the Qt4-interest mailing list about whether it is legal or not to create a commercial / proprietary application and statically link Qt4 to it. Although there are some unrealized ways to do this (by providing object files and Makefiles, etc. to the client), this doesn't seem like such a good idea after all.

One of my projects is to use Qt4 libraries licensed by LGPL, and I send them as separate DLLs / Dylibs / for my client using a simple installer on all platforms. While this works pretty well, I would like to optimize a) the size of the installer by reducing the size of the Qt library, just by including what I need, b) increase the speed of loading / downloading my application.

I am familiar with compiling Qt myself, but Qt got a lot of flags and switches.

Now I am building with the following flags:

./configure \ -fast \ -opensource \ -qt-sql-sqlite \ -nomake demos examples \ -silent \ -no-qt3support \ -no-gif \ -plugin-sql-mysql \ -release \ -no-xmlpatterns \ -no-multimedia 

I'm not quite sure what effect / influence the following flags have:

  • -no-stl
  • -no-javascript-jit
  • -no-nis
  • -separate-debug-info
  • -no-openvg
  • -no-mitshm

Is there anything else I can do, for example, by providing optimization switches for the compiler or by “removing” unused functions from the Qt built-in library to make it smaller (which would be easy with static assemblies). I do not have much experience with this.

Oh, like a side note, the size of my compiled application is about 600 kb (no split) when dynamically connected to Qt. I experimented with it and found that it is about 4 MB in size when I link statically; but in this case I will no longer need to include 40 MB of Qt libraries.

So, to put everything above in the question / request:

If you are more advanced than me on this topic, how do you optimize / deploy your own applications and make sure that they start quickly and contain only what you need?

+2
source share
4 answers

There are a few things I can think of:

  • use a compiler / linker combination that performs size optimization. MSVC is much better than MinGW, for example. All Qt release DLLs created using MSVC are ~ 21 MB. Built with MinGW, they are ~ 41 MB. By the way, do you really need to send all the DLLs?
  • use the generation flag -ltcg (Link-time code generation) to optimize between object files.
  • use preprocessor flags to exclude parts of Qt functionality. for example: QT_NO_STL = -no-stl.
  • try mmx / 3d now / sse2 flags
  • remove some styles (-no-style -)
+2
source

If you missed all the modules and didn’t feel that you didn’t need it, you can continue to use the qconfig tool (hidden in $ QTDIR / tools / tree) and delete the individual classes. Just beware of dependencies - you may need to repeat several times to get Qt to build (for example, QSpinBox depends on the presence of QValidator).

When building Qt, especially several times, the -nomake flag is an excellent wait time. Try the examples -nomake -nomake demos.

+2
source

Another optimization for overall speed is to use compiler optimizations when compiling Qt, but you need to edit some files. When you get Qt from Git, you will get qtbase / dir. First you run the configure script that qmake creates

Note: you can change Makefile.win32 or Makefile.unix and add lines, for example:

 QMAKE_CXXFLAGS_RELEASE = -CompilerDependentOptimizerSwitches 

if you want qmake to be optimized, but I don’t think it is really necessary, given that qmake runtime can be 0.0000001% of the total compilation time for a medium-sized application.

But real optimization arises when editing mkspecs, which are used to build Qt.

For example, in windows with VS2012, you will most likely change qtbase/mkspecs/win32-msvc2012/qmake.conf .

Ex .: default is Qt5.1, msvc2012 mkspec reads:

 QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE 

Since you want to optimize the size, you can replace it with:

 QMAKE_CFLAGS_RELEASE = -O1 -MD 

(According to http://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx )

Sometimes it includes the higher level mkspecs found in qtbase/mkspecs/common/ dir.

I successfully compiled Qt5.1 on Debian / g ++ 4.8.1 with -O3 -march=native (default is -O2 ) if it serves anyone.

After that, just run make in the root of Qt git and go to your team with beer, because even on a good computer it will take an age (about 2 hours on i7, without creating demos / examples, but with webkit).

0
source
 sed -i ' s@QMAKE _CXXFLAGS_THREAD += $$QMAKE_CFLAGS_THREAD@QMAKE _CXXFLAGS_THREAD += $$QMAKE_CFLAGS_THREAD -march=native@g ' qtbase/mkspecs/common/linux.conf 

Optimizes Qt5.8 for Linux

0
source

All Articles