• 编译 Qt 5.6(使QtWebEngine支持XP)


    说明

    qt 5.6的编译进行了数十遍,才得出本文的可行方案,之所以花了这么多的时间,主要是qt引入了QtWebEngine模块后,导致编译难度直线上升,而且又有一些中国特色的问题(如360安全卫士)导致,希望本文可以为大家节省更多的时间

    • 为什么要自己编?
      • 因为qt的预编译发行包中,QtWebEngine模块的QtWebEngineProcess.exe不能在xp下运行,是因为他们编译的时候没用支持xp的工具集导致的

    源码下载

    • Qt git地址:git://code.qt.io/qt/qt5.git
    • 推荐用 SourceTree 客户端来克隆源码

    准备工作

    • 系统 Windows 7 或者 Windows 10
    • 编译器 Visual Studio 2013 Update 5 或者 Visual Studio 2015 Update 1
    • 本文在以下4种情况下都编译通过
      • Windows 7 + Visual Studio 2013 Update 5
      • Windows 7 + Visual Studio 2015 Update 1
      • Windows 10 + Visual Studio 2013 Update 5
      • Windows 10 + Visual Studio 2015 Update 1
    • 安装Git,编译过程可能会启动 git.exe
    • 安装ActivePerl
    • 安装Python
    • 编译ICU库
    • 编译openssl
    • 编译webkit需要的环境
    • 最重要的准备工作
      • 保持编译过程中联网
      • 关闭360等安全卫士,杀毒软件,编译过程中360会弹框拦截
      • 将系统的区域改成 英语(美国),否则编译QtWebEngine会失败,如图所示

    可能遇到的编译错误

    • 使用 vs2013 编译的时候,有可能会遇到以下错误

      1
      Error 2 error C2440: 'default argument' : cannot convert from 'const wchar_t [1]' to 'const BSTR'   (srcGAudioOutput.cc) C:Program Files (x86)Windows Kits8.1Includeumsapi.h 16917 1 qgroundcontrol

      遇到这个问题,需要修改 qtbasemkspecscommonmsvc-base.conf 文件,将下面这段删除,如图

    • 使用 VS2015 Update2/Update3 编译时遇到以下错误

      1
      2
      ...skedge.cpp(231): error C2220: warning treated as error - no 'object' file generated
      ...skedge.cpp(231): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

      解决办法:使用5.6.1或者5.7.0版本的qt

      参考链接:QtWebEngine does not build with VS2015 SP2

    编译

    • 新建一个 environment.bat,用来执行环境变量的设置,代码如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      @echo off

      rem 设置vs安装路径
      set MSVC_PATH=C:Program Files (x86)Microsoft Visual Studio 14.0

      rem 设置icu源码路径,在编译icu时用到,编译qt用不到源码
      set ICU_SRC_PATH=C:UserskingDocumentsWorkspaceQtuildicu-sourcesource

      rem 设置icu编译安装的路径,在编译icu时用到,编译qt用不到这个格式的路径,注意安装路径格式,是linux风格
      set ICU_INSTALL_PATH=/cygdrive/C/Users/king/Documents/Workspace/Qt/build/icu

      rem 设置CYG依赖,在编译icu时用到,编译qt用不到
      set CYG_WIN_PATH=C:UserskingDocumentsdevcygwin64in

      rem 设置ICU编译安装的路径,编译Qt会用到,注意格式,是Windows风格
      set ICU_INSTALL_PATH_WIN=C:UserskingDocumentsWorkspaceQtuildicu

      rem 设置openssl源码路径,在编译openssl时用到,编译qt用不到源码
      set OPENSSL_SRC_PATH=C:UserskingDocumentsWorkspaceQtuildopenssl-1.0.1p

      rem 设置openssl的最终安装路径,编译qt时会用到
      set OPENSSL_INSTALL_PATH=C:UserskingDocumentsWorkspaceQtuildopenssl

      rem 设置编译Qt的编译器配置文件名
      set QMAKESPEC=win32-msvc2015

      rem 设置qt的源码路径
      set QT5_SRC_PATH=C:UserskingDocumentsWorkspaceQtqt5

      rem 设置qt编译后的安装路径
      set QT5_INSTALL_PATH=C:UserskingDocumentsWorkspaceQtqt_5.6.0

      rem 设置git安装路径
      set GIT_PATH=C:Program FilesGit

      rem 设置Perl的bin路径
      set PERL_PATH=C:UserskingDocumentsdevPerlin

      rem 设置python安装路径
      set PYTHON_PATH=C:Program Files (x86)Python27

      rem qtwebkit依赖环境
      set WIN_FLEX_BISION_PATH=D:Devwin_flex_bison-latest
      set SQLITE3SRCDIR=D:Devsqlite-amalgamation-3110100
      set RUBY_PATH=D:DevRuby22in

      rem 执行MSVC环境设置
      call "%MSVC_PATH%VCvcvarsall.bat" x86
    • 新建一个 build_qt.bat,用来执行qt的编译,代码如下

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      @echo off

      rem 调用前一个bat,执行环境变量的设置
      call environment.bat

      rem 将qt相关的路径加入path变量,为什么qtbaselib也加进去,因为编译过程中会执行qt自己编出来的exe,会依赖qt相关的dll,所以也加进去,git路径也加进来,保证编译过程中可以找到git.exe
      set PATH=%QT5_SRC_PATH%qtbasein;%QT5_SRC_PATH%qtbaselib;%QT5_SRC_PATH%gnuwin32in;%GIT_PATH%in;%PATH%

      rem 将qtrepotoolsin路径加入path环境变量
      set PATH=%QT5_SRC_PATH%qtrepotoolsin;%PATH%

      rem 将perl,python加入path
      set PATH=%PATH%;%PERL_PATH%;%PYTHON_PATH%

      rem 设置icu和openssl库的引用路径
      set LIB=%LIB%;%ICU_INSTALL_PATH_WIN%lib;%OPENSSL_INSTALL_PATH%lib

      rem 设置icu和openssl库的头文件引用路径
      set INCLUDE=%INCLUDE%;%ICU_INSTALL_PATH_WIN%include;%OPENSSL_INSTALL_PATH%include

      rem 将icu和openssl的bin目录加入PATH环境变量,icu的lib路径也加入PATH,是因为编译过程中运行的一些exe依赖icu库的dll
      set PATH=%PATH%;%ICU_INSTALL_PATH_WIN%in;%OPENSSL_INSTALL_PATH%in;%ICU_INSTALL_PATH_WIN%lib

      rem 进入qt源码目录
      cd /D %QT5_SRC_PATH%

      rem 配置qt,-target xp是支持xp系统,不然编出来的exe在xp下不能运行,比如QtWebEngineProcess.exe
      rem 可选参数 -force-debug-info:release版本也生成PDB文件
      call %QT5_SRC_PATH%configure -prefix %QT5_INSTALL_PATH% -debug-and-release -opensource -confirm-license -opengl dynamic -mp -icu -openssl -nomake examples -nomake tests -target xp -skip qtwebkit -no-directwrite

      rem 执行编译
      nmake

      rem 执行安装
      nmake install

      rem 复制openssl和icu到qt安装目录中
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicudt56.dll" "%QT5_INSTALL_PATH%in"
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicuin56.dll" "%QT5_INSTALL_PATH%in"
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicuuc56.dll" "%QT5_INSTALL_PATH%in"
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicudt.lib" "%QT5_INSTALL_PATH%lib"
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicuin.lib" "%QT5_INSTALL_PATH%lib"
      xcopy /y /k "%ICU_INSTALL_PATH_WIN%libicuuc.lib" "%QT5_INSTALL_PATH%lib"

      xcopy /y /k "%OPENSSL_INSTALL_PATH%inlibeay32.dll" "%QT5_INSTALL_PATH%in"
      xcopy /y /k "%OPENSSL_INSTALL_PATH%inssleay32.dll" "%QT5_INSTALL_PATH%in"
      xcopy /y /k "%OPENSSL_INSTALL_PATH%liblibeay32.lib" "%QT5_INSTALL_PATH%lib"
      xcopy /y /k "%OPENSSL_INSTALL_PATH%libssleay32.lib" "%QT5_INSTALL_PATH%lib"

      pause
    • 双击执行 build_qt.bat,整个编译过程可能需要4、5个小时,如果按照本文从头一步一步下来,应该可以一遍就编成功

    • 新建一个 build_qtwebkit.bat,用来执行qtwebkit的编译,代码如下

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      @echo off

      call environment.bat

      set LIB=%LIB%;%ICU_INSTALL_PATH_WIN%lib;%OPENSSL_INSTALL_PATH%lib;%QT5_INSTALL_PATH%lib
      set INCLUDE=%INCLUDE%;%ICU_INSTALL_PATH_WIN%include;%OPENSSL_INSTALL_PATH%include;%QT5_INSTALL_PATH%include
      set PATH=%QT5_INSTALL_PATH%in;%WIN_FLEX_BISION_PATH%;%ICU_INSTALL_PATH_WIN%in;%OPENSSL_INSTALL_PATH%in;%ICU_INSTALL_PATH_WIN%lib;%QT5_SRC_PATH%gnuwin32in;%PERL_PATH%;%PYTHON_PATH%;%RUBY_PATH%;%PATH%

      cd /D %QT5_SRC_PATH%

      %PERL_PATH%perl %QT5_SRC_PATH%qtwebkitToolsScriptsuild-webkit --qt

      pause
    • 如果要重新编译,需要清除之前编译的临时文件,可以新建一个 clean_qt.bat 来执行清理工作,代码如下

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      @echo off

      rem 调用前一个bat,执行环境变量的设置
      call environment.bat

      rem 将qt相关的路径加入path变量,为什么qtbaselib也加进去,因为编译过程中会执行qt自己编出来的exe,会依赖qt相关的dll,所以也加进去,git路径也加进来,保证编译过程中可以找到git.exe
      set PATH=%QT5_SRC_PATH%qtbasein;%QT5_SRC_PATH%qtbaselib;%QT5_SRC_PATH%gnuwin32in;%GIT_PATH%in;%PATH%

      rem 将qtrepotoolsin路径加入path环境变量
      set PATH=%QT5_SRC_PATH%qtrepotoolsin;%PATH%

      rem 将perl,python加入path
      set PATH=%PATH%;%PERL_PATH%;%PYTHON_PATH%

      rem 进入qt源码目录
      cd /D %QT5_SRC_PATH%

      rem 下面这句是用来清除所有的编译临时文件,有需要时再打开注释,比如想从头开始重新编译
      git submodule foreach --recursive "git clean -dfx"

    http://wangjie.rocks/2015/12/28/compile-qt/

  • 相关阅读:
    JavaScript 继承机制设计思想
    JavaScript里的原型(prototype), 原型链,constructor属性,继承
    centos7用yum安装node.js v8.x
    sequelize 字段无法操作
    开发CLI命令行
    微信分组群发图文40152,微信分组群发图文invalid group id hint
    微信分组群发45028,微信分组群发has no masssend quota hint
    微信45028错误,微信has no masssend quota hint错误
    微信上传图文消息素材40007,invalid media_id hint
    Spring文件上传出错:java.lang.ClassCastException: org.apache.catalina.connector.Request
  • 原文地址:https://www.cnblogs.com/findumars/p/6339333.html
Copyright © 2020-2023  润新知