// 一下為個人筆記,比較淩亂,勿怪.........
Google V8 引擎使用 版本資訊:2014-02-25: Version 3.25.3
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/[email protected] 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/7915763
(以上很多都可以在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類不是很熟悉,不好修改。
附代碼:
// V8_test.cpp : 定義控制台應用程式的入口點。
//
//https://developers.google.com/v8/get_started
#include "stdafx.h"
#include "v8.h"
//#pragma comment(lib,"v8_base.ia32.lib")
//#pragma comment(lib,"v8_nosnapshot.ia32.lib")
//#pragma comment(lib,"v8_snapshot.lib")
//v8 need this 使用V8需要連結ws2_32.lib和winmm.lib
//#pragma comment( lib,"ws2_32.lib" )
//#pragma comment(lib,"winmm.lib")
using namespace v8;
//v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate) {
// // Create a template for the global object.
// return v8::Context::New(isolate);
//}
int _tmain(int argc, _TCHAR* argv[])
{
v8::Isolate* isolate = Isolate::GetCurrent();
HandleScope handle_scope(isolate);
Handle<v8::Context> context = Context::New(isolate);
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);
context->Enter();
// Run the script to get the result.
Handle<Value> result = script->Run();
// Dispose the persistent context.
context->Exit();
// Convert the result to an ASCII string and print it.
String::Utf8Value utf8(result);
printf("%s\n",utf8);
return 0;
}
編譯注意,本人采用的是在編譯器連結中加入的附加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就出來啦。有問題請留言。
附錄文章: 見《V 8 編譯 二》