• 编译 Google V8 Script Engine


     

    1.下载安装

     

    a) Python 2.7.0

            安装到E:\Python27后,path环境变量加上 ;E:\Python27;E:\Python27\Scripts

    b)Scons-2.0.1.win32.exe

    http://sourceforge.net/projects/scons/files/scons/2.0.1/scons-2.0.1.win32.exe/download

    安装时,会自动识别到Python的安装目录,一路next就可以。安装完后,会在E:\Python27\Scripts生成一个scons.bat文件。

    c)Google V8 Script Engine

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

    windows 上直接用TortoiseSvn下载到d:\v8

     

    2.编译v8 源代码

    打开Visual Studio 2005 Command Prompt 命令行,输入以下命令,

    a)静态编译

    Cd /d d:\v8
    scons  mode=release library=static snapshot=on
    编译成功后,会生成v8.lib, 文件大小有200M,有点吓人。

    b)动态编译

    Cd /d d:\v8
    scons  mode=release library=shared snapshot=on
    编译成功后,会生成v8.dll 2M多及v8.lib导入库

     

    3.编写v8 Hello world

    这里主要就是用到v8.lib,v8.h 两个文件 ,简单的运行一段javascript脚本,输出Hello world

     D:\v8\Hello_world.cpp

     

    #include <v8.h>
    
     
    
    using namespace v8;
    
     
    
    int main(int argc, char* argv[]) {
    
     
    
      // Create a stack-allocated handle scope.
    
      HandleScope handle_scope;
    
     
    
      // Create a new context.
    
      Persistent<Context> context = Context::New();
    
      
    
      // Enter the created 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::New("'Hello' + ', World!'");
    
     
    
      // Compile the source code.
    
      Handle<Script> script = Script::Compile(source);
    
      
    
      // Run the script to get the result.
    
      Handle<Value> result = script->Run();
    
      
    
      // Dispose the persistent context.
    
      context.Dispose();
    
     
    
      // Convert the result to an ASCII string and print it.
    
      String::AsciiValue ascii(result);
    
      printf("%s\n", *ascii);
    
      return 0;
    
    }
    

    编译

    cl Hello_world.cpp  /I include v8.lib ws2_32.lib v8.lib winmm.lib

    链接静态库v8.lib的时候非常慢,大概需要10秒左右。反之使用v8 动态库的方式,就比较正常了,一秒都不需要.

    运行截图

    image

     

     

    参考文章

    How to Download and Build V8

    http://code.google.com/apis/v8/build.html

    v8 Building on Windows

    http://code.google.com/p/v8/wiki/BuildingOnWindows

    google V8配置过程中的一些问题

    http://hi.baidu.com/superkiki1989/blog/item/5c388fefc1902bdf2f2e21a4.html

    在线google文档

    http://bespin.cz/~ondras/html/classv8_1_1TryCatch.html#2811e500fbb906ee505895a3d94fc66f

     

     

     

     

     

     

  • 相关阅读:
    产品设计理应遵循哪些原则?
    产品经理必读的九步法
    exec
    Class convert
    Connecting method
    ASP.NET读写操作
    Encrypt Decrypt
    EventHandler, EventArgs
    Convert using code
    Dictionary List
  • 原文地址:https://www.cnblogs.com/foxhengxing/p/2103430.html
Copyright © 2020-2023  润新知