您的位置:首页 > 编程语言 > Qt开发

Windows平台下使用VS2012编译Qt-4.8.7源代码及单独编译qtwebkit-2.3.4

2015-08-20 06:09 746 查看
Windows 编译Qt比在OS X和Ubuntu下要困难得多,这是一件费力不讨好的的事情,主要问题在编译QtWebkit;但是开源的乐趣也在于每个人都能获得源代码,进行自定义编译。官方网站提供了MSVC2010预编译版本,在MSVC2012环境下无法使用;在http://sourceforge.net/projects/qt64ng/提供各种Windows平台下的非官方预编译Qt和QtCreator。
Windows平台下编译Qt花费了近2周的时间,按照网上许多编译教程得到的QtWebkit4.dll运行时出现错误(StackHash_0a9e),但是sourceforge.net上的非官方Qt的QtWebkit4.dll是正确的,开发者虽然给出了configure参数,但是没有给出具体编译步骤,依然无法编译出正确的QtWebkit4.dll;功夫不负有心人,终于搜索到一个编译的教程:
http://www.linuxfromscratch.org/blfs/view/svn/x/qt4.html
尽管是Linux平台下的教程,但是提供了一个QtWebkit源代码下载地址:
http://download.kde.org/stable/qtwebkit-2.3/2.3.4/src/qtwebkit-2.3.4.tar.gz
国内镜像可以从下面的地址下载:
http://mirrors.ustc.edu.cn/kde/stable/qtwebkit-2.3/2.3.4/src/qtwebkit-2.3.4.tar.gz

VS2012编译器安装与使用

安装Visual Studio 2012 Express for Desktop

使用Developer Command Prompt for VS2012终端来进行编译,下面的操作均采用这种方式;如果使用普通终端,则需要将C:\Program Files\Microsoft Visual Studio 11.0\VC\bin设为系统路径,并且每次开启后运行vcvars32.bat

编译OpenSSL

参考:/article/5298830.html

先安装perl
http://www.activestate.com/activeperl

下载源代码
http://www.openssl.org/source/openssl-1.0.2d.tar.gz
解压缩到C:\Users\username\Downloads\openssl-1.0.2d

首先,切换到Openssl代码的根目录
cd C:\Users\username\Downloads\openssl-1.0.2d

如果你安装了NASM,可以用汇编的形式编译,以加快Openssl的运行速度
执行下面两句
perl Configure VC-WIN32 --prefix=C:\OpenSSL
ms\do_nasm

如果不想使用汇编编译,则执行下面两句就可以
--prefix是指定你要把OpenSSL安装的位置
perl Configure VC-WIN32 no-asm --prefix=C:\OpenSSL
ms\do_ms

开始编译
nmake -f ms\ntdll.mak

安装到prefix指定的目录中
nmake -f ms\ntdll.mak install

编译-no-webkit的Qt-4.8.7

Building Qt-4.8.7 with MSVC 2012 express for Windows Desktop

下载Qt源代码(可以从中科大开源镜像下载)
解压缩

切换到源代码根目录,执行编译配置(注意:不要采用-fast选项):
configure -mp -prefix C:\Qt\4.8.7 -release -confirm-license -opensource -qt-zlib -qt-libjpeg -qt-libpng -qt-libmng qt-libtiff -no-qt3support
-no-webkit -nomake demos -nomake examples -openssl -I C:\OpenSSL\include -L C:\OpenSSL\lib

编译
namke
耗时约2小时

安装
namke install

添加C:/Qt/4.8.7/bin到系统路径PATH

编译qtwebkit for Qt-4.8.7

参考:
http://trac.webkit.org/wiki/QtWebKit
http://trac.webkit.org/wiki/BuildingQtOnWindows

First of all you need a version of Qt for Windows. If you are an Open Source developer then you can download the Open Source Edition of Qt for Windows from the Nokia Website:http://qt.nokia.com/downloads

Note that you need to enable ICU support in the Qt build (also seehttp://doc-snapshot.qt-project.org/5.0/requirements-win.html)
Make sure that Qt is configured with-openssl if you want HTTPS support in
QtWebKit. You will need the non-light version of

Win32 OpenSSL libraries.

Install
ActiveState Perl
Install
Python 2.x (and add the installation location to your PATH)
Install
Ruby (1.9.3 and 2.x should both work)

The following external GNU tools are needed from theGnuWin32 Project:

Bison

GPerf

Grep
Flex (or win_flex fromhere)
LibIconv (needed for bison)
Make (not necessary if you want to build using MSVC)

You'll also need
SQLite for revisions after
r95919 in 2011 AND especially for the unofficial
QtWebKit-2.3 (as mentioned in these
mailing
list
threads). Read the notes below for it.

Please install these tools in a path without spaces (i.e. not in "C:\Program Files")
Make sure the GnuWin32 packages are in your PATH as well as Perl and Python. You also need to have %QTDIR% set and have %QTDIR%\bin in your PATH.
If you have Cygwin's bin directory in your path, make sure that it comes after ActiveState Perl and GnuWin32. You might have to remove it completely from your PATH if you have problems with slashes and backslashes while building using MinGW.mingw32-make
and GnuWin32's make will use sh.exe to run commands if they find it in the PATH.

下载qtwebkit-2.3.4源代码:
webkit.org上下载的最新源代码运行perl Tools\Scripts\build-webkit —qt —release并没有成功,可能是Windows下webkit编译与编译器版本有较大关系。
国内镜像可以从下面的地址下载:
http://mirrors.ustc.edu.cn/kde/stable/qtwebkit-2.3/2.3.4/src/qtwebkit-2.3.4.tar.gz

安装编译WebKit所需的环境:

GNUWIN32
http://sourceforge.net/projects/gnuwin32/
或者Qt-5.5.0源代码中的gunwin32目录

python
https://www.python.org/ftp/python/2.7.10/python-2.7.10.msi

ruby
https://www.ruby-lang.org/en/downloads/

perl
http://www.activestate.com/activeperl

sqlite source code
http://sqlite.org/2015/sqlite-amalgamation-3081101.zip
解压缩到
C:\Users\username\Downloads\sqlite3

编译,打开Developer Command Prompt for VS2012终端,执行:

set SQLITE3SRCDIR=C:\Users\username\Downloads\sqlite3
set QTDIR=C:\Qt\4.8.7
perl Tools\Scripts\build-webkit --qt --release

耗时近4小时

安装
cd WebKitBuild/Release
nmake install

测试QtWebkit

实际上,QtWebkit编译完成后,在WebKitBuild/Release/bin目录下已经生成了一个示例程序:QtTestBrowser.exe

现在我们来编译Qt源代码demos/browser项目
切换到项目目录下,执行:
mkdir build-browser
cd build-browser
qmake ..
nmake

运行release/browser.exe

失败的尝试

编译qt源代码中的QtWebkit无需上述依赖(python,ruby,bison等),但是应该编译openssl。这里列举一些对源代码进行处理的步骤,经过处理的源代码虽然编译通过,但是QtWebkit4.dll是有问题的,无法运行。

处理mkspec/win32-msvc2012/qmake.conf

QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t-
改为:
QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t

MSVC2012 编译Qt-4.8.6 webkit会遇到一些问题(HashSet.h),在Qt-4.8.7中已经得到解决。

由代码里面的非英文的引号造成的错误,src\3rdparty\webkit\Source\WebCore\platform下的DefaultLocalizationStrategy.cpp,定位到327行:

platform\DefaultLocalizationStrategy.cpp(327) : error C2001: newline in constant
platform\DefaultLocalizationStrategy.cpp(327) : fatal error C1057: unexpected end of file in macro expansion
原始的错误代码如下:
return WEB_UI_STRING("Look Up “<selection>”", "Look Up context menu item with selected word").replace("<selection>", truncatedStringForLookupMenuItem(selectedString));
注意<selection>前后的引号,就是它造成编译报错。修改成下面的代码:
return WEB_UI_STRING("Look Up \"<selection>\"", "Look Up context menu item with selected word").replace("<selection>", truncatedStringForLookupMenuItem(selectedString));

由于文件命名导致的错误(奇怪,Mac和Ubuntu下都没有这个问题)C:\Users\username\Downloads\qt-everywhere-opensource-src-4.8.7\src\3rdparty\webkit\Source\WebCore\inspector\front-end\Images

c:\Users\username\Downloads\qt-everywhere-opensource-src-4.8.7\qt-everywhere-opensource-src-4.8.7\bin\rcc.exe -name WebKit ..\..\WebCore\inspector\front-end\WebKit.qrc -o tmp\rcc\release_shared\qrc_WebKit.cpp
RCC: Error in '..\..\WebCore\inspector\front-end\WebKit.qrc': Cannot find file '
Images\breakpointConditionalCounterBorder.png'
NMAKE : fatal error U1077: 'c:\Users\username\Downloads\qt-everywhere-opensource-src-4.8.7\qt-everywhere-opensource-src-4.8.7\bin\rcc.exe' : return code '0x1'

Stop.
原文件扩展名为.pn,应为.png

如果试图单独编译src\3rdparty\webkit\Source\WebKit.pro项目,仍然出现下面的错误:

inspector\InspectorController.cpp(146) : error C2661: 'WebCore::InspectorBackendDispatcher::InspectorBackendDispatcher' : no overloaded function takes 11 arguments

编译QtCreator-2.8.1
Building QtCreator-2.8.1 with Qt-4.8.7 and MSVC 2012

编译过程中会出现下面的错误,原因是编译安装Qt时少了一些头文件:
c:\users\username\downloads\qt-creator-2.8.1-src\src\libs\utils\consoleprocess
_p.h(49) : fatal error C1083: Cannot open include file: 'private\qwineventnotifi
er_p.h': No such file or directory
winutils.cpp
Generating Code...
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 11.0\VC\BI
N\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 11.0\VC\BI
N\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.

C:\Users\username\Downloads\qt-everywhere-opensource-src-4.8.7\src\corelib\kernel中的头文件拷贝到新建目录C:\Qt\4.8.7\include\QtCore\private

编译过程:
#对于普通的终端,请运行:vcvars32.bat
#CONFIG+=release可以防止生成的qtcreator.exe运行时先弹出一个终端窗口
qmake CONFIG+=release qtcreator.pro

namke

namke install INSTALL_ROOT=C:\Qt\qtcreator-2.8.1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: