I have 5..0.2 MinGW Static Build. Now what?
-
I think I've correctly done a static build of 5.0.2, but how do I get a statically linked executable?
I'm running Window 7, 64 bit.
For the record, there's what I did to build 5.0.2.
- I downloaded
qt-windows-opensource-5.0.2-mingw47_32-x86-offline
otherwise known as "Qt 5.0.2 for Windows 32 bit (MinGW 4.7)" - I uncompressed it to my "Documents" directory, in a "Qt" folder.
- Created a file called "qt5vars.cmd" in Qt/5.0.2/Src/qtbase whose contents are
@
set PATH=C:\Users\RSF\Documents\Qt\5.0.2\Src\qtbase;C:\Users\RSF\Documents\Qt\5.0.2\Src\qtbase\bin;C:\Users\RSF\Documents\Qt\5.0.2\Src\qtbase;C:\users\RSF\Documents\Qt\Tools\MinGW\bin;C:\Perl\bin;%PATH%
set QMAKESPEC=win32-g++
@- Performed several edits. In qtbase/mkspecs/win32-g++/qmake.conf, I changed to these settings
@ QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
QMAKE_LFLAGS = -static -static-libgcc
DEFINES += QT_STATIC_BUILD@- And in qtbase/qmake/Makefile.win32-g++, I changed to
@LFLAGS = -static -static-libgcc@
- Opened up a windows command tool, cd-ed to qtbase and ran the qt5vars.cmd script.
- Ran
@configure -static -debug-and-release -opensource -opengl desktop
-platform win32-g++ -qt-zlib -qt-libpng -qt-libjpeg -nomake examples
-make libs@- Ran mingw32-make.
All of the above seemed to work out just fine, but now what? How do I link my executable statically so that it will run without Qt and without any separate dlls?
There are some directions here
http://qt-project.org/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc
but things have changed significantly since they were written. I tried variations on what's there, but nothing seems to work.Also, what changes are needed in the .pro file? Is it enough to add the line "CONFIG += static"? Is there any other secret magic that one needs to perform?
In most respects, Qt is really nice, but as soon as you want to share what you've done the entire build process becomes a nightmare. This would be acceptable if I were doing something strange, like cross-compiling for a PalmPilot using the Rasperry Pi, but all I want is a Windows app.
- I downloaded
-
Well...it never fails. As soon as I ask someone, I figure it out myself. Judging by the number of hits on Google concerning this topic, I'm not the only one having trouble. For those in the same circle of Hell that I was just in, here are the last missing steps.
Go to QtCreator, under Tools->Options. Then coose "Build and Run" and the "Qt Versions" tab. Click the "Add..." button and go to qtbase/bin/qmake.exe. Name this something like "static" under "Version Name."
Now, go to the "Compilers" tab. Click "Manual," then the "add" button and choose "MinGW." Browse to get the same directory path as for the instance(s) under "Auto-detected."
Assuming that you have a project going already, to compile it statically, go to the "Projects" icon (along the left side). Click the "Manage Kits" button at the top-left. Under the "Kits" tab, click the item under "Manual." For "Compiler" choose "MinGW" and under "Qt version" choose the "static" version (or whatever you named these before).
Now in the upper left, you should be able to choose the "Add Kit" button to choose the new "static" kit.
The entire process is far (!) from obvious. I hope this helps someone.