V8 引擎编译 测试 64位+VS2012

本文介绍如何在64位Win7环境下使用Visual Studio搭建V8 JavaScript引擎。包括安装必备工具、配置环境变量、下载依赖库及生成解决方案等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

V8是一个由丹麦Google开发的开源JavaScript引擎 环境 win7 64+visual studio 
参考文档: 官网帮助http://code.google.com/p/v8/wiki/BuildingWithGYP

 

Visual Studio 

  首先我们需要安装一个tortoisesvn工具。官网http://tortoisesvn.net/downloads.html
下载对应的64位版本打开运行 默认一个控件不安装 选择所有控件都安装 。

 

在 硬盘的D盘下面新建个V8文件夹 用来存在V8引擎的源代码 右击文件名
点击SVN checkout 

URL 中填入

http://v8.googlecode.com/svn/trunk  

点击ok 自动开始下载文件

将SVN的安装目录添加到环境变量 系统变量 PATH里面。

启动CMD 
根据官方帮助 需要下载3个依赖集。

Python  cygwin icu gyp

1、python 安装

 在命令行中输入
svn co http://src.chromium.org/svn/trunk/tools/third_party/python_26@89111 third_party/python_26
将C:\Users\xiaofan\third_party\python_26 添加到系统环境变量中

2、cygwin 安装
svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@231940 third_party/cygwin

 

3、icu 安装
svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu46 third_party/icu

4、Gyp安装 

svn co http://gyp.googlecode.com/svn/trunk build/gyp

  进入 GYP目录 在CMD python setup.py install  安装

5、生成all.sln文件

进入V8根目录下

python build\gyp_v8 如果添加了环境变量重启CMD 运行 

没有则 third_party/python_26/python.exe build\gyp_v8 -Dtarget_arch=x64
运行完成之后在V8 build 下面会生成解决方案all.sln 直接使用visual studio 打开 编译生成我们需要的库

特别注意,此时有三个编译选项:

        1)、指定vs版本:-G msvs_version=2010,这里指定后续使用vs2010打开sln。

        2)、指定静态或动态库:-Dcomponent=shared_library,这里指定sln编译生成v8动态库,如果不加这个选项默认是v8静态库 

        3)、指定sln库的版本:-Dtarget_arch=64,这里指定生成64位的sln,当然需要64位的vs打开,如果不加这个选项默认是32位

 

  由于我的环境是64+VS2012 期望生成动态

python build\gyp_v8 -G msvs_version=2012 -Dcomponent=shared_library

 我得到
 
  只需要在你的程序中 #include”v8.h”

#pragma comment(lib,”v8.lib”)

所有的头文件都在V8include文件里面 copy到工程目录

需要的库都在gyp Debug 或者RElese 里面

 将这3DLL 复制到跟程序一个目录 实现 就行。

   例子:
#include "v8.h"

#include<Windows.h>

#include<stdio.h>

#pragma comment(lib,"Winmm.lib")

#pragma comment (lib,"v8.lib")

 

using namespace v8;

#pragma comment(lib,"ws2_32.lib")

 

int main(int argccharargv[]) {

  // Get the default Isolate created at startup.

  Isolate* isolate = Isolate::GetCurrent();

 

  // Create a stack-allocated handle scope.

  HandleScope handle_scope(isolate);

 

  // Create a new context.

  Handle<Context> context = Context::New(isolate);

 

  // Enter the context for compiling and running the hello world script.

  Context::Scope context_scope(context);

 

  // Create a string containing the JavaScript source code.

  Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");

  

  // Compile the source code.

  Handle<Script> script = Script::Compile(source);

  

  // Run the script to get the result.

  Handle<Value> result = script->Run();

  

  // Convert the result to an UTF8 string and print it.

  String::Utf8Value utf8(result);

  printf("%s\n", *utf8);

  system("pause");

  return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值