項(xiàng)目中需要用到webkit,調(diào)研了webkit源碼,但是源碼比較龐大壶栋,用xcode編譯很方便,但是本人不熟悉mac下編程普监,所以研究了一段時(shí)間之后只能作罷贵试。后來(lái)了解到Qtwebkit做了不少精簡(jiǎn)的工作,而且qt對(duì)跨平臺(tái)比較友好凯正,所以轉(zhuǎn)而研究Qtwebkit毙玻。研究第一步是要編譯Qt和Qtwebkit,本文記錄了VS2015靜態(tài)編譯Qt5.5.1的過(guò)程廊散,參考了網(wǎng)上相關(guān)文章桑滩,做了一些補(bǔ)充和修改。
安裝需要的工具
以下使用的庫(kù)和工具的版本都是編譯機(jī)器是用的版本允睹,其他版本沒(méi)有嘗試运准。
- python 使用2.7.14版本
- ruby 使用25-x64版本,ruby官網(wǎng)文檔要求安裝
- perl 使用5.24缭受,編譯webkit和OpenSSL需要
- win_flex windows編譯webkit需要
- vs2015胁澳,安裝的時(shí)候需要勾選VC工具
源碼編譯目錄
qt
icu-58.2-vs2015
openssl-1.0.2o
win_flex_bison
qt-everywhere-opensource-src-5.5.1
編譯ICU和OpenSSL
- ICU 如果直接靜態(tài)編譯需要修改官網(wǎng)的腳本,比較麻煩米者,好消息是有人已經(jīng)靜態(tài)編譯過(guò)了韭畸,通過(guò)這里可以直接下載編譯好的版本,這里使用的是v58.2塘雳,注意v59.1與webkit有沖突(主要是UCHAR的問(wèn)題)
- OpenSSL 網(wǎng)上已經(jīng)有很多windows下編譯OpenSSL的文章了陆盘,這里參考的是這篇文章,
修改Qt靜態(tài)編譯參數(shù)
打開(kāi)\qt-everywhere-opensource-src-5.5.1\qtbase\mkspecs\common\msvc-desktop.conf败明,修改以下編譯參數(shù)隘马。
QMAKE_CFLAGS_RELEASE = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MDd
改為
QMAKE_CFLAGS_RELEASE = -O2 -MT
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MTd
修改zlib編譯報(bào)錯(cuò)
修改\qt-everywhere-opensource-src-5.5.1\qt3d\src\3rdparty\assimp\assimp.pri,將
contains(QT_CONFIG, system-zlib) {
unix|mingw: LIBS += -lz
else: LIBS += zdll.lib
} else {
INCLUDEPATH += $$[QT_INSTALL_HEADERS/get]/QtZlib
}
修改為
contains(QT_CONFIG, system-zlib) {
if (unix|mingw): LIBS += -lz
else: LIBS += zdll.lib
} else {
git_build: \
INCLUDEPATH += $$[QT_INSTALL_HEADERS/get]/QtZlib
else: \
INCLUDEPATH += $$[QT_INSTALL_HEADERS/src]/QtZlib
}
編譯Qt
REM Set up Microsoft Visual Studio 2015
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
ECHO ON
SET _CD=%CD%
SET _PATH=%PATH%
SET PATH=%PATH%;G:\qt\ninja-1.8.2\
SET PATH=%PATH%;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin
SET PATH=%PATH%;C:\python3.6\Scripts\;C:\python3.6\
SET PATH=%PATH%;C:\Ruby25-x64\bin
SET ICU_PCM_DIR=%_CD%\icu-58.2-vs2015
SET OPENSSL_DIR=%_CD%\openssl-1.0.2o
SET QT_SOURCE=%_CD%\qt-everywhere-opensource-src-5.8.0
SET QT_PREFIX=%_CD%\Qt5.5.1\qt-static
REM Setting ICU
SET PATH=%PATH%;%ICU_PCM_DIR%\bin
REM Building Qt
CALL %QT_SOURCE%\configure -confirm-license -opensource -platform win32-msvc2015 ^
-debug-and-release -static -force-debug-info^
-prefix %QT_PREFIX% ^
-qt-sqlite -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype ^
-nomake tests -nomake examples ^
-icu -I %ICU_PCM_DIR%\include -L %ICU_PCM_DIR%\lib^
-openssl-linked -I %OPENSSL_DIR%\include -L %OPENSSL_DIR%\lib ^
ICU_LIBS_DEBUG="-lsicudtd -lsicuind -lsicuucd -lAdvapi32" ^
ICU_LIBS_RELEASE="-lsicudt -lsicuin -lsicuuc -lAdvapi32" ^
OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" ^
OPENSSL_LIBS_DEBUG="-llibeay32MTD -lssleay32MTD" ^
OPENSSL_LIBS_RELEASE="-llibeay32MT -lssleay32MT"
nmake && nmake install
CD /D %_CD%
SET PATH=%_PATH%
運(yùn)行腳本可能出現(xiàn)的問(wèn)題:
- 可能會(huì)出現(xiàn)【rc.exe comamnd not found】妻顶,這個(gè)需要將C:\Program Files (x86)\Windows Kits\8.1\bin\x86(可能你的機(jī)器不是這個(gè)路徑)加到PATH下
- 在make install的時(shí)候出現(xiàn)了拷貝異常酸员,出現(xiàn)在拷貝\qttranslations\translations的時(shí)候,修改下\qttranslations\translations\Makefile.Debug和\qttranslations\translations\Makefile.Release相關(guān)的路徑即可
- 編譯ASSIMP過(guò)程中報(bào)【找不到zlib.h】讳嘱,這個(gè)參考前面的zlib編譯報(bào)錯(cuò)進(jìn)行修改
編譯Qtwebkit
REM Set up \Microsoft Visual Studio 2015
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
ECHO ON
SET _CD=%CD%
SET _PATH=%PATH%
SET BUILD_MODE=debug
SET ICU_PCM_DIR=%_CD%\icu-58.2-vs2015
SET QT_SOURCE=%_CD%\qt-everywhere-opensource-src-5.5.1
SET QT_PREFIX=%_CD%\Qt5.5.1\vs2015-32
SET QTWEBKIT_PREFIX=%_CD%\Qt5.5.1\Qtwebkit
set PATH=%PATH%;%QT_PREFIX%\bin;%QT_SOURCE%\gnuwin32\bin;%_CD%\win_flex_bison
set INCLUDE=%INCLUDE%;%QT_PREFIX%\include;%ICU_PCM_DIR%\include;
set LIB=%LIB%;%QT_PREFIX%\lib;%QT_PREFIX%\plugins;%QT_PREFIX%\plugins\audio;%QT_PREFIX%\plugins\bearer;^
%QT_PREFIX%\plugins\designer;%QT_PREFIX%\plugins\geoservices;%QT_PREFIX%\plugins\iconengines;^
%QT_PREFIX%\plugins\imageformats;%QT_PREFIX%\plugins\mediaservice;%QT_PREFIX%\plugins\platforms;^
%QT_PREFIX%\plugins\playlistformats;%QT_PREFIX%\plugins\position;%QT_PREFIX%\plugins\printsupport;^
%QT_PREFIX%\plugins\qml1tooling;%QT_PREFIX%\plugins\qmltooling;%QT_PREFIX%\plugins\sensorgestures;^
%QT_PREFIX%\plugins\sensors;%ICU_PCM_DIR%\lib;
perl %QT_SOURCE%\qtwebkit\Tools\Scripts\build-webkit --qt --%BUILD_MODE% --prefix=%QTWEBKIT_PREFIX%
CD /D %QT_SOURCE%\qtwebkit\WebKitBuild\%BUILD_MODE%
nmake install
CD /D %_CD%
SET PATH=%_PATH%
運(yùn)行腳本可能出現(xiàn)的問(wèn)題:
- 無(wú)法解析的外部符號(hào)【 initializeTestFonts】幔嗦,錯(cuò)誤如下:
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:..\..\bin\QtTestBrowser.exe @C:\Users\Ring\AppData\Local\Temp\nm3ED0.tmp
正在創(chuàng)建庫(kù) ..\..\bin\QtTestBrowser.lib 和對(duì)象 ..\..\bin\QtTestBrowser.exp
qttestbrowser.obj : error LNK2019: 無(wú)法解析的外部符號(hào) "__declspec(dllimport) void __cdecl WebKit::QtTestSupport::initializeTestFonts(void)" (__imp_?initializeTestFonts@QtTestSupport@WebKit@@YAXXZ),該符號(hào)在函數(shù) "private: void __thiscall LauncherApplication::handleUserOptions(void)" (?handleUserOptions@LauncherApplication@@AAEXXZ) 中被引用
..\..\bin\QtTestBrowser.exe : fatal error LNK1120: 1 個(gè)無(wú)法解析的外部命令
需要修改\qt-everywhere-opensource-src-5.4.2\qtwebkit\Source\WebCore\platform\qt\QtTestSupport.h文件沥潭,將
#if defined(BUILDING_WEBKIT)
#define TESTSUPPORT_EXPORT Q_DECL_EXPORT
#else
#define TESTSUPPORT_EXPORT Q_DECL_IMPORT
#endif
修改為
#if defined(BUILDING_WEBKIT)
#define TESTSUPPORT_EXPORT /*Q_DECL_EXPORT*/
#else
#define TESTSUPPORT_EXPORT /*Q_DECL_IMPORT*/
#endif
- 第一次編譯Qtwebkit的時(shí)候碰到了無(wú)法解析的外部符號(hào)【 registerExtendedCodecs】邀泉,這個(gè)將ICU的版本換成v58.2之后再編譯就沒(méi)有出現(xiàn)了,如果出現(xiàn)了請(qǐng)參考這里
使用VS2015建立Qtwebkit項(xiàng)目
遇到的問(wèn)題:
- 運(yùn)行項(xiàng)目之后出現(xiàn)【nextafter】錯(cuò)誤,具體原因沒(méi)有找汇恤,通過(guò)斷點(diǎn)可以找到\qt-everywhere-opensource-src-5.5.1\qtwebkit\Source\WTF\wtf\MathExtras.h庞钢,將
inline double nextafter(double x, double y) { return _nextafter(x, y); }
修改為
inline double nextafter(double x, double y) { return x > y ? x - DBL_EPSILON : x + DBL_EPSILON; }
然后重新編譯webkit即可
參考列表:
- http://www.ituring.com.cn/article/195148
- https://www.cnblogs.com/findumars/p/5133709.html
- http://wiki.qt.io/Building_Qt_5_from_Git#Windows
- https://codereview.qt-project.org/#/c/127252/3/src/3rdparty/assimp/assimp.pri
- https://www.cnblogs.com/qnkk123/p/7305892.html
- https://blog.csdn.net/liang19890820/article/details/51658574
- https://blog.csdn.net/syrchina/article/details/50804091