Google v8

OS:Window 7

1.下载v8 zip:https://github.com/v8/v8,解压zip,重命名v8-master文件夹为v8。

2.下载安装svn:http://tortoisesvn.net/downloads.html。安装后确认C:Program FilesTortoiseSVNin被加到环境变量path

3.在v8根目录下Check out gyp

运行cmd:cd v8,切换到v8的根文件夹

运行cmd: svn co http://gyp.googlecode.com/svn/trunk build/gyp, gyp安装到v8/build/gyp

4.在v8根目录下Check out ICU

运行cmd:svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu46 third_party/icu

5.在v8根目录下Check out cygwin

运行cmd:svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@231940 third_party/cygwin

6.下载安装python 2.7.X:http://www.python.org/download/,安装后将python.exe的路径添加到path环境变量中

7.运行cmd:python buildgyp_v8 -Dtarget_arch=x64(注:按装python后要打开新的cmd窗口,并且当前目录切换到v8的根文件夹)

8.运行cmd:"C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdev
env.exe" /build release buildall.sln,或者用VS2010打开v8uildall.sln, build. Build成功后在v8uildReleaselib生成
v8_base.x64.lib,v8_nosnapshot.x64.lib,v8_snapshot.lib,icui18n.lib,icuuc.lib。

9.用VS2010创建一个c++ Win32 Console Application,添加x64 build配置。在linker里面导入v8_base.x64.lib,v8_nosnapshot.x64.lib,v8_snapshot.lib,icui18n.lib,icuuc.lib,ws2_32.lib,winmm.lib。

10.Copy/Paste以下代码到main函数

#include <v8.h>

using namespace v8;

int main(int argc, char* argv[]) {
  // 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
", *utf8);
  return 0;
}

11.Build,如果出现以下linker error,添加msvcprtd.lib;MSVCRTD.lib到linker/input/Ignore Specific Default Libriries

>LIBCMT.lib(memcpy.obj) : error LNK2005: memmove already defined in MSVCRTD.lib(MSVCR100D.dll)

 

原文地址:https://www.cnblogs.com/ldlchina/p/v8_HelloWorld.html