Ubuntu Linux 下 Google Chrome V8引擎的編譯實戰

來源:互聯網
上載者:User

大名鼎鼎的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的部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.