大名鼎鼎的Chrome V8引擎大家應該都知道了,我就不廢話多說,不知道的可以去Google Code搜尋。
不過不得不提的是Google Chrome V8引擎的開發人員拉斯巴克(Lars Bak)。他是一個編程天才,卻遠離電腦世界的核心,在丹麥為Google工作,
這個工作地方是一個邊遠的農場,環境很優美。
編譯環境
在編譯之前先看一下我的機器環境:
1. Linux yuchao-Latitude-E5410 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux
2. gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
3. GNU Make 3.81 這個程式建立為 i686-pc-linux-gnu
4. GNU ld (GNU Binutils for Ubuntu) 2.20.51-system.20100908
5. svn,版本 1.6.12 (r955767)
6. Python 2.6.6
7. SCons by Steven Knight et al.:
script: v2.0.0.final.0.r5023, 2010/06/14 22:05:46, by scons on scons-dev
engine: v2.0.0.final.0.r5023, 2010/06/14 22:05:46, by scons on scons-dev
特別說明:SCons 是一個用 Python 語言編寫的類似於 make 工具的程式。與 make 工具相比較,SCons 的設定檔更加簡單清晰明了,
除此之外,它還有許多的優點。本文將簡單介紹如何在軟體開發項目中使用 SCons,通過本文,讀者可以學習到如何使用 SCons 來建造自己的程式項目。
編譯步驟:
1. 用如下命令得到v8原始碼:svn checkout http://v8.googlecode.com/svn/trunk/ v8
2. 進入原始碼目錄,使用如下命令產生動態串連庫,如果要編譯成為debug模式的版本,需要加參數mode=debug,命令如下:
scons mode=debug library=shared snapshot=on
3. 如果要編譯成為shell解釋模式,需要加參數sample=shell,命令如下:
scons sample=shell
4. 如果要編譯為開發人員版本,使用如下命令:
scons d8
5. 編譯完成後你可以得到如下檔案:libv8preparser_g.so 、libv8_g.so 、shell、 d8
如果你沒有看到這幾個檔案,說明你沒有配置成功或者編譯有誤。
測試編譯結果
使用目錄下面的helloworld.cc的測試檔案:
#pragma comment(lib,"libv8.a")#include "include/v8.h"using namespace v8;int main(int argc, char *argv[]){ String source = String::New("'Hello'+',world I'm YuChao from SINA'"); Script script = Script::Compile(source); Value result = script->Run(); String::AsciiValue ascii(result); printf("%s\n",*ascii); return 0;}
最後可以看到輸出:Hello world I'm YuChao from SINA,說明你的編譯是可以啟動並執行。
另外設計一個JS指令碼,使用如下命令執行JS指令碼:
shell [options] -e string execute string in V8 shell [options] file1 file2 ... filek run JavaScript scripts in file1, file2, ..., filek shell [options] shell [options] --shell [file1 file2 ... filek] run an interactive JavaScript shell d8 [options] file1 file2 ... filek d8 [options] d8 [options] --shell [file1 file2 ... filek] run the new debugging shell
你同樣可以測試編譯是否成功。
Windows下的編譯過程請參考如下網址:http://code.google.com/p/v8/wiki/BuildingOnWindows
本文來自:CYBEREXP2008的部落格