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

来源:互联网 发布:刷手怎么找淘宝商家 编辑:程序博客网 时间:2024/05/29 21:31

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

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

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

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

[plain] view plaincopy在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 plaincopy在CODE上查看代码片派生到我的代码片
  1. return WEB_UI_STRING("Look Up “<selection>”", ...);  

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

[cpp] view plaincopy在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 plaincopy在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 plaincopy在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 plaincopy在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,大功告成。


参考文章:

  • 1. 编译QT4.8.2完成之后,mingw32-make install时出错的解决方案
  • 2. VS2010+QT5.1.0静态库编译
  • 3. QTCN开发网>Qt安装与发布>[提问]mingw32编译QT5
  • 4. Problems when building/installing Qt5.1.0x64 under Win7x64 VS2010SP1 for different source and installation folders
  • 5. Qt 5.1.0 RC MinGW32 静态编译 Static Build
  • 6. [编译] QT编译./configure参数的详细解释[新手充电必读]
  • 7. Qt 4.8.2 VS2008 集成环境搭建过程中编译错误的解决办法
0 0
原创粉丝点击