visual studio 2010 编译 google v8

本文介绍如何在Windows和Ubuntu环境下从源代码编译V8 JavaScript引擎,并提供了一个简单的示例来展示如何使用V8进行JavaScript代码的执行。

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

win7 + vs2010

how to build:
http://code.google.com/p/v8/wiki/BuildingWithGYP

svn:
http://tortoisesvn.net/downloads/

python(2.7):
http://www.python.org/download/


download source and build in command lines:

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

Change to v8 dir and do the rest:
2. svn checkout http://gyp.googlecode.com/svn/trunk build/gyp

3. svn checkout http://src.chromium.org/svn/trunk/deps/third_party/cygwin@66844 third_party/cygwin

4. add python's dir such as "c:\python27" to PATH env.

5. python build\gyp_v8 -Dtarget_arch=ia32 -Dcomponent=shared_library
   python build\gyp_v8 -Dtarget_arch=x64
   python build\gyp_v8 -Dtarget_arch=ia32

all.sln will be generated in "build" subdir.

6. "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com" /build Release build\All.sln


7. copy v8.dll to windows system32 dir.


* errors may occur when compiling preparser using shared_library mode, ignore it or:
  edit preparser.vcxproj in preparser dir under v8, replace all "USING_V8_SHARED" with "BUILDING_V8_SHARED".

* path problems may occur when compiling using IDE, use command line please.



//////////////////////////////////////////////////////////////////////
Ubuntu 12

svn + python + gcc + make

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

2. cd v8

3. make dependencies

4. make native mode=debug library=shared snapshot=on

5. sudo  cp  ./out/native/lib.target/libv8.so  /usr/lib/


//////////////////////////////////////////////////////////////////////

// Hello world for Visual Studio

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


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);

    // Here's how you could create a Persistent handle to the context, if needed.
    Persistent<Context> persistent_context(isolate, context);

    // 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();

    // The persistent handle needs to be eventually disposed.
    persistent_context.Dispose();

    // Convert the result to an ASCII string and print it.
    String::AsciiValue ascii(result);
    printf("result: %s\n", *ascii);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值