Google V8 编译方法(visual c++ 2008 express)(学习+原创)
參考資料:
?
(不同 VS 版本的可以看這里,有很詳細介紹的,不過是鳥文··)http://code.google.com/p/v8/wiki/BuildingOnWindows
http://code.google.com/p/v8/
http://www.cnblogs.com/sweetwxh/archive/2011/09/11/2173596.html
?
?
?
一、準備工作
?
1???????? TortoiseSVN
?
2????????? V8?? Engine源代碼,從Google的SVN當中Check Out出來,最新版本地址。
?
3????????? Python 2.6.x? (必須是 2.6版本的)
?
4????????? Scons,與Make工具類似的編譯工具
?
?
二、 下載安裝:
?1.? 安裝? tortoiseSVN ,
?2 .?? 根據(jù)V8 的地址 (http://v8.googlecode.com/svn/trunk/)下載下來:
?3.? 安裝Python2.6.x(我安裝的是 2.6.6 ), 設(shè)置環(huán)境變量?
?4.? 安裝Scons,Scons也需要設(shè)置環(huán)境變量,它的目錄是Python安裝目錄下的Scripts。
?
注意: python 安裝之后,才安裝 scons ,scons是安裝在python的目錄下的。
?
三、編譯(我用的是 , visual? c++ 2008 express)
1. 打開 CMD
2.導航到下載的v8源代碼根目錄,就是有一個SConstruct文件(Scons就是根據(jù)它來編譯程序的)的目錄。
3. 使用 scons在該目錄下 編譯, 編譯參數(shù)不同版本會不一樣,
可以看:http://code.google.com/p/v8/wiki/BuildingOnWindows
這里只介紹 visual c++ 2008 express 的
?
先看幾個參數(shù):(其他的參數(shù)可以去官網(wǎng)看)
(1)?????? env ?????: ??env="INCLUDE:%INCLUDE%,LIB:%LIB%"?? (具體路徑看下面)
(2)?????? mode ???: ??release /debug
(3)?????? msvcrt ??: ??shared/static (動態(tài)庫/靜態(tài)庫)
?
根據(jù)自己的需求編譯,編譯完成后,會在根目錄生產(chǎn)v8.lib, v8.dll ,? v8_g.lib v8_g.dll, 在其他程序中使用V8需要用到這兩個庫文件以及v8的頭文件。
建議編譯成動態(tài)庫,靜態(tài)庫的話很大,而且HELLOWORD 編譯鏈接的時候都要很久。
?
例子:
(1)(編譯為 release 版本, 動態(tài)庫)
scons env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\Microsoft Visual Studio 9.0\VC\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"libary=shared mode=release msvcrt=shared –j4
?
?
(2)編譯為 DEBUG 版本, 動態(tài)鏈接庫
scons env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\Microsoft Visual Studio 9.0\VC\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"libary=shared mode=debug msvcrt=shared verbose=on
?
?
或者
:
(1)?????? 打開VS里面的選項 : tools\visual studio 2008 command promopt
或者
進入Windows平臺,進入命令后先運行,以初始化vc編譯環(huán)境。
cmd /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
?
(2)?????? 導航到下載的v8源代碼根目錄
(3)?????? 不用寫 env 的參數(shù)
(4)?????? 根據(jù)需要選擇編譯參數(shù):
(5)?????? 例如:
scons mode=debug verbose=on library=shared msvcrt=static
?
?
?
建個自己的 Hello World!
?
(1)???? 從官網(wǎng)下代碼:
代碼如下:
?
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
? // Create a stack-allocated handle scope.
? HandleScope handle_scope;
? // Create a new context.
? Persistent<Context> context = Context::New();
?
? // 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();
?
? // Dispose the persistent context.
? context.Dispose();
? // Convert the result to an ASCII string and print it.
? String::AsciiValue ascii(result);
? printf("%s\n", *ascii);
? return 0;
}
?
(2)把 頭文件 和.lib 文件包含進去
?
如果編譯的時候出現(xiàn)鏈接錯誤 ,可以把這兩個庫也加進去,就可以啦
?"C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib\Winmm.lib"
?"C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib\WSock32.lib"
?
(3)運行的結(jié)果就是: 控制臺輸出 :hello world!
轉(zhuǎn)載于:https://www.cnblogs.com/gdutbean/archive/2012/02/27/2369724.html
總結(jié)
以上是生活随笔為你收集整理的Google V8 编译方法(visual c++ 2008 express)(学习+原创)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据类型范围》
- 下一篇: 金山词霸2012不能在PDF中取词 解决