[原创]Windows下Google V8 javascript引擎编译

时间:2021-09-06 04:43:27

项目用到将v8嵌入到C++的情况,公司没时间研究,只有在家研究,编译过程一堆坑。记录一下。

网上百度的都是基于vs2010,或者早版本的v8编译,最新版本应该使用vs2013\vs2015。本文介绍的是2016-04-12下载最新版本v8源代码情况下的v8编译。

0x01 准备工作

    下载安装:git\svn\python27

0x02 V8源代码

v8源代码托管于 https://chromium.googlesource.com/v8/v8.git,要FQ。

github上有镜像同步的源,可以从这里下载:https://github.com/v8/v8

0x03 gyp

  在以前版本的v8中,在tools/visual_studio下似乎有编译工程,最新版本的已经移除。需下载gyp生成对应的编译设置。

这个网上有下载,不知道怎么从v8 wiki中给的 http://code.google.com/p/gyp/ 地址进行下载,于是从github找到了镜像:

https://github.com/bnoordhuis/gyp/tree/master/pylib/gyp

下载后放到build/gyp目录下即可

0x04 cygwin和icu

在third_party目录下新建cygwin/icu两个目录,分别使用svn从下面两个地址下载对应代码:

     svn co https://src.chromium.org/chrome/trunk/deps/third_party/cygwin
           svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu52

cygwin建议从其他地方下载,当时下来至少半小时啊。。

0x05 clang

在tools/clang/scripts目录下,通过svn下载:

svn co https://src.chromium.org/chrome/trunk/src/tools/clang/scripts
0x06 depot_tools

关于这个库,好像网上都没有怎么提,需要下载到和build同级的depot_tools目录下:

   可以从google的托管网站上下:git clone https://chromium.googlesource.com/chromium/tools/depot_tools

但那个慢啊,我从github上找了个最近的clone,下了个zip包解压:https://github.com/mlufei/depot_tools

0x07 编译

启动命令行工具,由于我装的是VS2013,设置环境变量:

set DEPOT_TOOLS_WIN_TOOLCHAIN=0  ; 不设置这个会自动去下载sdksetup.exe

set GYP_MSVS_VERSION=2013

好了,现在最坑爹的问题来了,编译提示:

src/tracing/trace-event.h(10): fatal error C1083: Cannot open include file: 'base/trace_event/common/trace_event_common.h': No such file or director

trace_event_common.h这个文件,无论是从镜像还是google自身的托管仓库都找不到。好吧,想办法去找吧。

将文件放到\base\trace_event\common\trace_event_common.h后,重新编译,

然后又会遇到下面的编译警告,由于工程将警告视为错误,编译不过:

warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss

这是由于相关文件中含有unicode字符,删除即可。

当目前为止,除测试用例相关的工程都应该可以编译通过了。我这里编译后\build\Debug\lib目录下是这个样子的:

[原创]Windows下Google V8 javascript引擎编译