Swollen EXE sizes and unwanted dependencies with Qt / MingW

I am trying to figure out how to reduce the size of EXE files compiled in the latest QT SDK (4.8.2) (based on mingw / g ++). I was working on a vanilla C ++ based console application that has a simple loop and only # turns on iostream when I noticed that the exe generated by it is about 465 KB; way more than they should be! Commenting on the entire stream, he reduces it to the expected range of 5 kilobytes (although the remaining code will be mostly dead). This is not at all true, especially since another, complete project that I am working on has a QGLwidget, a window, a dozen data structures and ~ 3000 operators, and only a clock with a speed of about 126 KB. Are there any settings or a flag that I am missing? Here's the .pro, while cpp is trivial and Qt-free (basically getline and cout with half a dozen char swaps):

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
QMAKE_CXXFLAGS_RELEASE += -O2
QMAKE_CXXFLAGS_RELEASE += -Os

I tried several other configurations and it definitely compiles in release mode (debug is> 3Mb), but I can't understand why it was so bloated.

I also looked at the PE header, and I see that it imports some functions from libgcc_s_dw2-1.dll and mingwm10.dll, and it would be nice if I could completely eliminate these dependencies, especially since none of them must be required. I can get libgcc to leave (due to 17kb exe size) by adding QMAKE_LFLAGS_RELEASE += -staticto .pro, but mingwm10.dll remains anyway, calling one function.

, ( , ). , , , , -DQT_LARGEFILE_SUPPORT -mthreads. ( ):

  • 14:04:00: conTest...
  • 14:04:00: , qmake.
  • 14:04:01: : "C:\QtSDK\mingw\bin\mingw32-make.exe"
  • C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Release
  • mingw32-make [1]: `C:/Documents and Settings/Administrator/My Documents/QT/conTest '
  • g++ -c -O2 -O2 -Os -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -I "c:\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\win32-g++" -o release\main.o main.cpp g++ -Wl, -s -Wl, -, -mthreads -o release\conTest.exe release/main.o
  • mingw32-make [1]: `C:/Documents and Settings// /QT/conTest '
  • 14:04:10: "C:\QtSDK\mingw\bin\mingw32-make.exe" .
+5
2

mingw , binutils w32 ( , ). , binutils , :

http://sourceware.org/bugzilla/show_bug.cgi?id=11539

. , :

-fdata-sections -ffunction-sections

( GCC, Qt, ) :

-Wl,--gc-sections

. , 20 , , 10 . ( ), Qt, SDL - (, Vorbis, mpg123, FLAC ).

, Windows, . Linux - w32 , .

+3

-s. . , , .exe . . , .exe iostream, .

MinGW nm.exe, cmd . strip.exe .

+2

All Articles