Static Installation of Qt 4.6.2On Windows And QT Application Deployment
Recently I had to deploy an application I created using Qt on Windows. Inorder to keep things simple by only having a few files to deploy, i.e. astand-alone executable with the associated compiler specific DLLs, I had tobuild everything statically. After having a static installation of QT in my PC,I was able to build my application.
I am going to describe the procedure below, because I spent a few hoursuntil I finally succeed.
- First of all we have to download and install:
a. minGW from here.
b. QT libraries Windows from here.
- When we have finished with the above installations, we have to add minGW’s bin folder path into system PATH. The path is usually C:\MinGW\bin.
3. a. Right click-> My Computer
4. b. Properties-> Advanced Tab
5. c. EnvironmentVariables button
d. We append the following for PATH -> ;C:\MinGW\bin\
- The next step is to edit mkspecs (c:\Qt\4.6.2\mkspecs\win32-g++\qmake.conf) by findingQMAKE_LFLAGS and add–static:
QMAKE_LFLAGS = -static -enable-stdcall-fixup-Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
- Now we open a command prompt (Start->Run->”cmd” ) and go to C:\Qt\ 4.6.2 or wherever our Qt is installed.
- We initialize QMAKESPEC variable by typing:
set QMAKESPEC=win32-g++
- Next we type in our platform specific configuration option (inside C:\Qt\4.6.2). At this point we suppose that we also need sqlite support, so we use:
configure -static -release -no-exceptions -qt-sql-sqlite
After issuing the command QT will ask about the edition we are going to use. Ifwe use the Open Source Edition, we type ‘o’ and press enter:
C:\Qt\4.6.2>configure-static -release -no-exceptions -qt-sql-sqlite
Which edition of Qt do you want to use ?
Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.
>o
Next we have to accept the terms of the license by typing ‘y’:
This is the Qt for Windows Open Source Edition.
You are licensed to use this software under the terms of
the GNU Lesser General Public License (LGPL) version 2.1
or the GNU General Public License (GPL) version 3.
Type '3' to view the GNU General Public License version 3(GPLv3).
Type 'L' to view the Lesser GNU General Public Licenseversion 2.1 (LGPLv2.1).
Type 'y' to accept this license offer.
Type 'n' to decline this license offer.
Do you accept the terms of the license?
>y
Finally the configuration step will start and will take some time, depending onthe system.
- When the configuration step completes we issue:
mingw32-make sub-src
which may take a while…(you can have a coffee, or two….)…
- Now the installation process has been completed.
We can now build our application.
In order to link the static libraries in our application we:
• Open a command prompt and go to the project’s folder.
• We issue:
set QMAKESPEC=win32-g++
qmake -project
qmake *.pro
mingw32-make clean
qmake -config release
• In the .pro file of your project, make sure we include this line:
CONFIG += static
• Now we have the application’s executable, which we can deploy on a PChich does not have QT installed.
so that it will compile the libraries statically.
• If we also need the SQL library, we add:
QT += sql
in the .pro file.
• And finally we build the application by issuing:
mingw32-make
===================================================
发现新问题:
编译 debug 版 app 的时候,给出错误:
c:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtGuid
需要把 C:\Qt\4.7.3\lib 下面的 libQtGuid4.a 拷贝出一个 libQtGuid.a
c:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtCored
需要把 C:\Qt\4.7.3\lib 下面的 libQtCored4.a 拷贝出一个 libQtCored.a
编译 debug 版的静态库:
mingw32-make sub-src debug
这样生成的静态库很大,编译出来的 app 达到 200多M。