用mingw静态编译Qt4.8.2和Qt5.1.1

因为一些乱七八糟的原因,我需要用mingw静态编译Qt4.8.2和Qt5.1.1。
经历了一天的折腾之后,自觉编译一下Qt还是件颇为麻烦的事情,故将过程略作总结,以备不时之需。

首先,在编译之前,我需要下载mingwqt-everywhere-opensource-src-4.8.2qt-everywhere-opensource-src-5.1.1

然后,准备开始编译了,当然先得把压缩包解压到一个合适的地方。
我这里的路径是"C:\Qt"下面。

解压完毕后,先试着编译Qt4.8.2。
configure命令为:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. configure -confirm-license -opensource -prefix "C:\Qt\Qt4.8.2" -debug-and-release -static -platform win32-g++ -nomake demos -nomake examples -nomake tests -fast  

使用的选项说明:

-confirm-license -opensource 选择开源协议并确认
-prefix "C:\Qt\Qt4.8.2" 指定安装目录为"C:\Qt\Qt4.8.2"
-debug-and-release 编译debug和release版
-static 编译成静态库
-platform win32-g++ 使用mingw编译
-nomake demos -nomake examples -nomake tests 不编译这些不需要的东西
-fast 快速编译

在控制台下进入"C:\Qt\qt-everywhere-opensource-src-4.8.2",运行configure。
在编译之前,需要改一个地方:
找到"qt-everywhere-opensource-src-4.8.2\src\3rdparty\webkit\Source\WebCore\platform"下的DefaultLocalizationStrategy.cpp文件,第327行:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. return WEB_UI_STRING("Look Up “<selection>”", ...);  

把它改成这样:(注意引号)

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. return WEB_UI_STRING("Look Up <selection>", ...);  

否则编译会报错。

然后运行mingw32-make开始编译。
编译完毕后,找到"qt-everywhere-opensource-src-4.8.2\src\winmain"下的Makefile.Debug文件,第215行:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. @$(CHK_DIR_EXISTS) c:$(INSTALL_ROOT)/Qt/Qt4.8.2/lib/pkgconfig $(MKDIR) c:$(INSTALL_ROOT)/Qt/Qt4.8.2/lib/pkgconfig   

改成:(注意$(CHK_DIR_EXISTS)和目录的斜杠)

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. @if not exist c:$(INSTALL_ROOT)\Qt\Qt4.8.2\lib\pkgconfig $(MKDIR) c:$(INSTALL_ROOT)\Qt\Qt4.8.2\lib\pkgconfig   

改完后用同样的方式修改Makefile.Release。

最后mingw32-make install,大功告成。

接下来编译Qt5.1.1。
首先还是configure命令:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. configure -confirm-license -opensource -prefix "C:\Qt\Qt5.1.1" -debug-and-release -static -platform win32-g++ -opengl desktop -no-angle -nomake examples -nomake tests -skip qtwebkit  

使用的选项说明:(重复的就不写了)

-opengl desktop 选择desktop的opengl,不这样玩编译会挂
-no-angle 不使用angle,否则编译会挂
-nomake examples -nomake tests 不编译这些东西。其中examples,参加编译的话install会挂
-skip qtwebkit 不编译qtwebkit,否则很麻烦

在控制台下进入"C:\Qt\qt-everywhere-opensource-src-5.1.1\qtbase",运行configure。
之后依次mingw32-make、mingw32-make install,大功告成。


参考文章:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值