Static Installation of Qt 4.6.2On Windows And QT Application Deployment

本文详细介绍了如何在Windows系统上静态安装Qt4.6.2并部署Qt应用程序,包括下载安装必备组件、配置环境变量、编辑mkspecs文件、配置Qt版本和接受许可协议等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

  1. First of all we have to download and install:
    a.    minGW from here.
    b.    QT libraries Windows from here.

 

  1. 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\

 

  1. 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

 

  1. Now we open a command prompt (Start->Run->”cmd” ) and go to C:\Qt\ 4.6.2 or wherever our Qt is installed.

 

  1. We initialize QMAKESPEC variable by typing:

set QMAKESPEC=win32-g++

 

  1. 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.

  1. When the configuration step completes we issue:

mingw32-make sub-src


which may take a while…(you can have a coffee, or two….)…

  1. 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。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值