最新Google V8 引擎编译

转自:http://blog.csdn.net/liuzhihan209/article/details/20255611

//            

一下为个人笔记,比较凌乱,勿怪.........


Google V8 引擎使用

V8 引擎是 Google 的一个开源项目,是一个高效的 JavaScript 引擎,它可以作为一个独立的库被嵌入到已有的 C++ 应用之中,为软件的灵活性,扩展性提供可能。使用 V8 的另外一个好处是,你不需要重新学习一本脚本语言,JavaScript 已经广泛的被开发人员,尤其是前端开发人员所使用。


最新版本的下载地址:http://code.google.com/p/v8/wiki/Source


  下载方式:git  /SVN

         两种方式都很简单,在git  shell 中输入命令即可。

                  git 下载地址:http://git-scm.com/download/

                  下载后安装,打开Git  Bash,Linux 命令,切换到要下载的目录,输入 ::git clone git://github.com/v8/v8.git v8  即可,会看到目录下自动创建了V8 文件夹。

                   SVN类似。

           提供已经全部下载好的源码下载地址:

                  下载好了,就需要编译了,可参考原版的说明,最清晰了。

             Building 说明地址:http://code.google.com/p/v8/wiki/BuildingWithGYP

              ,列举了很多编译的可选项,我们就需要在WIndows下就需要重点参考这里了,地址:http://code.google.com/p/v8/wiki/BuildingWithGYP#Visual_Studio

             其实说明的很简单的,需要下载4个工具即可,

              1.Python,  注意这里用的2.7的,不要用最新版的3.3的,否者会报错(Python呢 最新版的语法改动导致)

                           下载地址:http://python.org/downloads/    选择2.7.6 的即可。

              2.cygwin。

                           可以选择使用SVN,下载地址:svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@231940 third_party/cygwin

                           也可以到CSDN这里下载:http://download.csdn.net/detail/liuzhihan209/6983931

              3.ICU.

                           下载地址:http://pan.baidu.com/s/1kZFWi

             4.gyp

                          下载地址:http://download.csdn.net/detail/liuzhihan209/6983931

                      (以上很多都可以在Google中SVN 到,但是貌似速度太慢了)

                  这里只有Python 需要安装,安装之后需要配置系统环境变量,在Path中加入你的Python安装目录即可,我的:D:\Python 2.7.6\;

             在V8目录下新建,third_party文件夹,将Cygwin 和Icu  解压后放入,将gyp放入V8\build下即可。

                   在cmd 中,先切换到V8 目录下,输入 python   build\gyp_v8 ,很简单的命令,利用python编译。

             一般成功后就会在build下看到all.sln。即表示生成成功了。

                      打开all.sln  编译生成即可。 个人表示上面没什么特别的难处。

             

                附编译好的lib,Debug和Release。

                下载地址:http://download.csdn.net/detail/liuzhihan209/6984147


             测试代码  V8_test.            

                 最新代码地址(假如你使用的最新的V8,那么测试代码就需要最新)Google 官方 HelloWorld:https://developers.google.com/v8/get_started

              很多人下载的最新的代码,目前百度的很多代码都是旧版的,所以此处会报错。加之对V8类不是很熟悉,不好修改。

             附代码:

  1. <span style="font-size:14px;">// V8_test.cpp : 定义控制台应用程序的入口点。  
  2. //  
  3. //https://developers.google.com/v8/get_started  
  4. #include "stdafx.h"  
  5.   
  6. #include "v8.h"  
  7. //#pragma comment(lib,"v8_base.ia32.lib")  
  8. //#pragma  comment(lib,"v8_nosnapshot.ia32.lib")  
  9. //#pragma comment(lib,"v8_snapshot.lib")   
  10.   
  11.   
  12. //v8 need this  使用V8需要链接ws2_32.lib和winmm.lib     
  13. //#pragma comment( lib,"ws2_32.lib" )     
  14. //#pragma comment(lib,"winmm.lib")   
  15.   
  16. using namespace v8;  
  17.   
  18. //v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate) {    
  19. // // Create a template for the global object.   
  20. //      return v8::Context::New(isolate);  
  21. //}  
  22.   
  23. int _tmain(int argc, _TCHAR* argv[])  
  24. {  
  25.          v8::Isolate* isolate = Isolate::GetCurrent();    
  26.           HandleScope handle_scope(isolate);    
  27.            
  28.           Handle<v8::Context> context = Context::New(isolate);    
  29.           Context::Scope context_scope(context);      
  30.     
  31.     // Create a string containing the JavaScript source code.       
  32.     Handle<String> source = String::NewFromUtf8(isolate,"'Hello' + ', World!'");      
  33.   
  34.     // Compile the source code.       
  35.     Handle<Script> script = Script::Compile(source);      
  36.     
  37.         context->Enter();    
  38.     
  39.     // Run the script to get the result.       
  40.     Handle<Value> result = script->Run();      
  41.     
  42.     // Dispose the persistent context.       
  43.     context->Exit();    
  44.    
  45.     // Convert the result to an ASCII string and print it.       
  46.     String::Utf8Value     utf8(result);     
  47.     printf("%s\n",utf8);  
  48.   
  49.     return 0;  
  50. }  
  51.   
  52. </span>  


                     编译注意,本人采用的是在编译器链接中加入的附加lib,属性,链接,附加依赖项:ws2_32.lib
                  v8_base.ia32.lib   v8_nosnapshot.ia32.lib    v8_snapshot.lib    icui18n.lib      icuuc.lib     winmm.lib,附加包含文件,就一个V8\include,即可。注意附加lib不可少,新版本的多了icui18n.lib,icuuc.lib,貌似不加会报错,可以自己测试下吧。

          然后就没有啦,OK,HelloWorld就出来啦。有问题请留言。

                    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值