webkit在vs2008中编译

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

webkit的官方网站写的webkit需要在vs2005的环境下编译,而我的机器只装了vs2008,我可不想在装一个vs2005.所以我就打算在vs2008里面试试编webkit,最终的结果是可以编译出来,但是运行不起来。

步骤如下:

1. 下载webkit代码。webkit使用svn下载后差不多有1G多,这里面的大部分代码是测试代码,由于网速慢加上现在不需要这些测试代码,我下载的是Nightly Builds代码(http://nightly.webkit.org/里面的Source),下载后只有十几兆。

2. 下载cygwin,最好按照http://webkit.org/building/tools.html里面的下载安装cygwin,不如后面编译时perl脚本会报错,原因是cygwin的某些模块没有安装,我就遇到过报确实Registry 模块的错。

你可以到WebKitTools/Scripts下看perl脚本,例如Registry 模块就是在num-cpus用的:

#!/usr/bin/perl

use strict;  
use warnings;

use Win32API::Registry 0.21 qw( :ALL );

my $key;  
my $i = 0;   
while (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE//DESCRIPTION//System//CentralProcessor//$i", 0, KEY_READ, $key)) {   
    $i++;   
    RegCloseKey($key);   
}

print "$i/n";

3. 我将cygwin是装在d盘,我不喜欢将东西装在c盘。所以我使用Junction将cygwin映射到c盘(Junction请参考http://blog.csdn.net/chief1985/archive/2009/08/16/4453475.aspx)。如果你将vs2005装在其他盘也可以使用这个方法进行映射。

4. 将webkit放到cygwin的home目录(cd ~)下。

cygwin的一些文章可以参考:

Cygwin的中文支持(解决乱码)

     为shell下执行svn命令设置代理

设置Cygwin的home目录

5. 下载WebKitSupportLibrary.zip,放到webkit目录下,不要解压。设置windows环境变量:

WEBKIT_DIR = C:/cygwin/home/xufan/WebKit

WEBKITLIBRARIESDIR = %WEBKIT_DIR%/WebKitLibraries/win

WEBKITOUTPUTDIR = %WEBKIT_DIR%/WebKitBuild

6. (可选)如果需要代理才能上网,需要修改一下WebKitTools/Scripts/update-webkit-auxiliary-libs这个脚本,我的修改如下:

use strict;  
use warnings;

use HTTP::Date qw(str2time);  
use File::Find;   
use File::Temp ();   
use File::Spec;   
use FindBin;   
use lib $FindBin::Bin;   
use webkitdirs;

sub lastModifiedToUnixTime($);

# Time in seconds that the new zip file must be newer than the old for us to  
# consider them to be different. If the difference in modification time is less   
# than this threshold, we assume that the files are the same. We need this   
# because the zip file is served from a set of mirrors with slightly different   
# Last-Modified times.   
my $newnessThreshold = 30;

my $sourceDir = sourceDir();  
my $file = "WebKitAuxiliaryLibrary";   
my $zipFile = "$file.zip";    
my $auxiliaryLibsURL = "http://developer.apple.com/opensource/internet/$zipFile";   
my $webkitLibrariesDir = toUnixPath($ENV{'WEBKITLIBRARIESDIR'}) || "$sourceDir/WebKitLibraries/win";   
my $tmpDir = File::Spec->rel2abs(File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1));

print "Checking Last-Modified date of $zipFile.../n";  
my $proxy="-x 192.168.4.9:9888";   
#my $proxy="";   
my $result = system "curl $proxy -s -I $auxiliaryLibsURL | grep Last-Modified > /"$tmpDir/$file.headers/"";    
print STDERR "Couldn't check Last-Modified date of new $zipFile./n" if $result;

if (!$result && open NEW, "$tmpDir/$file.headers") {  
    my $new = lastModifiedToUnixTime(<NEW>);   
    close NEW;

    if (defined $new && open OLD, "$webkitLibrariesDir/$file.headers") {  
        my $old = lastModifiedToUnixTime(<OLD>);   
        close OLD;   
        if (defined $old && abs($new - $old) < $newnessThreshold) {   
            print "Current $file is up to date/n";   
            exit 0;   
        }   
    }   
}

print "Downloading $zipFile.../n/n";  
$result = system "curl $proxy -o /"$tmpDir/$zipFile/" $auxiliaryLibsURL";   
die "Couldn't download $zipFile!" if $result;

$result = system "unzip", "-q", "-d", $tmpDir, "$tmpDir/$zipFile";  
die "Couldn't unzip $zipFile." if $result;

print "/nInstalling $file.../n";

sub wanted  
{   
    my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpDir/$file/win");   
    my $destination = "$webkitLibrariesDir/$relativeName";

    if (-d $_) {  
        mkdir $destination;   
        return;   
    }

    system "cp", $_, $destination;  
}

File::Find::find(/&wanted, "$tmpDir/$file");

$result = system "mv", "$tmpDir/$file.headers", $webkitLibrariesDir;  
print STDERR "Couldn't move $file.headers to $webkitLibrariesDir" . "./n" if $result;

print "The $file has been sucessfully installed in/n $webkitLibrariesDir/n";  
exit;

sub toUnixPath  
{   
    my $path = shift;   
    return unless $path;   
    chomp($path = `cygpath -u '$path'`);   
    return $path;   
}

sub lastModifiedToUnixTime($)  
{   
    my ($str) = @_;

    $str =~ /^Last-Modified: (.*)$/ or return;  
    return str2time($1);   
}

7.执行WebKitTools/Scriptsupdate-webkit,它会下载一些编译时要用的头文件和库。(我估计webkit主要是因为版权原因才不将这些头文件和库放到自己的代码里面)。如果没有出下载的进度的信息,一般是因为你在cygwin里面安装了Qt,你可以看一下环境变量里面有没有QTDIR,如果有,可以在home目录里面的.bashrc最下面加上一行 unset QTDIR

8.按照http://webkit.org/building/tools.html里面的提示安装QuickTime SDK

9. 执行WebKitTools/Scripts/build-webkit,这个必须执行,不如后面会报找不到stdint.h和stdbool.h头文件。如果你的vs不是装在c盘,一般会报错,这个没关系。cygwin里面的操作到此结束。

10.到WebKit/win/WebKit.vcproj/WebKit.sln双击打开。

11.按F7开始编译。

12.编译的时候会报treat warning as error错误,可以在vs2008里面的项目属性将treat warning as error改为NO

image

13.出错就进行12步里面的修改。如果你编译的是debug版,可能要将WebKitLibraries/win/lib里面的lib文件加_debug,例如将pthreadVC2.lib改为pthreadVC2_debug.lib

14.经过1个多小时的编译,会编译出webkit.dll(放在WebKitBuild/bin下面)。

15. 将Safari里面的dll拷贝到WebKitBuild/bin下面,拷贝vs 2008的crt的dll。运行WinLauncher.exe会发现报错,用depends看一下webkit.dll的依赖关系,会发现webkit同时依赖了vs2005和vs2008的库。原因是因为从Safari里面拷贝的dll依赖于vs2005,而webkit是依赖于vs2008.

16.无法运行我觉得可以用下面两种方法解决(我没有试过,大家可以试试):

一。将vs2008里面的全局include和library该为指向vs2005的include和library目录,然后再编译

二。将webkit依赖的库用vs2008编一边。chrome里面有这些库。chrome将webkit依赖的库都变为了static lib,这样最终连接的webkit.dll依赖最小,而且不会出现我们现在遇到的问题。

三。cairo版的webkit依赖较小(起码不依赖苹果闭源的几个库),应该可以在vs2008里面编译和运行。

参考文章:

http://niuwa.org/2009/06/23/how-to-build-webkit-with-vs2005-on-windows/ (这个是我见过解释webkit编译最全的)

http://niuwa.org/tag/webkit/   
http://nightly.webkit.org/   
http://blog.csdn.net/northboy911/archive/2009/08/03/4405472.aspx   
http://hi.baidu.com/jiahuiren/blog/item/3aae94c7f2e09dd8d0006027.html

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/tduycc/article/details/83826120
今日推荐