Qt

From Electron Cloud

Revision as of 07:08, 14 October 2009 by Ecloud (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Static Windows executables with Qt and MinGW

Here is an excellent explanation of how to generate a statically linked EXE which does not require any DLLs at all: Qt and the MinGW runtime are both linked in. The summary:

Before configuring and compiling Qt, edit %qtdir%\mkspecs\win32-g++\qmake.conf and prepend -static to QMAKE_FLAGS

QMAKE_LFLAGS = -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc

Then:

configure -static -release -no-exceptions <your other flags>

and build Qt. Then in your application .pro file:

win32 {
QMAKE_LFLAGS += -static -static-libgcc -Lmingw32
}

Maybe some of those are redundant, but it worked for me. Sure enough, it ended up substantially smaller than the same app which had Qt statically linked but still depended on the mingw32 DLL, as if being 100% static enabled the linker to prune out some unused bits of code that it otherwise wasn't sure could be pruned or not.

Caveats are that you can't use threads or exceptions or Qt plugins.

Another approach might be to use an EXE bundler tool but I haven't tried that, since they seem to have their own drawbacks too (costing money, not being sure what it does exactly, entire DLLs taking up memory and yet linked in a non-reusable way with just one application).

In theory if you use Visual Studio 6 (or the corresponding free compiler from MS?), you don't need to redistribute a runtime DLL, but you'd still need the relevant Qt DLLs (or statically link them).

Personal tools