項目用到將v8嵌入到C++的情況,公司沒時間研究,只有在家研究,編譯過程一堆坑。記錄一下。
網上百度的都是基於vs2010,或者早版本的v8編譯,最新版本應該使用vs2013\vs2015。本文介紹的是2016-04-12下載最新版本v8源代碼情況下的v8編譯。
0x01 准備工作
下載安裝:git\svn\python27
0x02 V8源代碼
v8源代碼托管於
,要翻牆。github上有鏡像同步的源,可以從這里下載:https://github.com/v8/v8
0x03 gyp
在以前版本的v8中,在tools/visual_studio下似乎有編譯工程,最新版本的已經移除。需下載gyp生成對應的編譯設置。
這個網上有下載,不知道怎么從v8 wiki中給的 http://code.google.com/p/gyp/ 地址進行下載,於是從github找到了鏡像:
https://github.com/bnoordhuis/gyp/tree/master/pylib/gyp
下載后放到build/gyp目錄下即可
0x04 cygwin和icu
在third_party目錄下新建cygwin/icu兩個目錄,分別使用svn從下面兩個地址下載對應代碼:
svn co https://src.chromium.org/chrome/trunk/deps/third_party/cygwin
svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu52
cygwin建議從其他地方下載,當時下來至少半小時啊。。
0x05 clang
在tools/clang/scripts目錄下,通過svn下載:
svn co https://src.chromium.org/chrome/trunk/src/tools/clang/scripts
0x06 depot_tools
關於這個庫,好像網上都沒有怎么提,需要下載到和build同級的depot_tools目錄下:
可以從google的托管網站上下:git clone https://chromium.googlesource.com/chromium/tools/depot_tools
但那個慢啊,我從github上找了個最近的clone,下了個zip包解壓:https://github.com/mlufei/depot_tools
0x07 編譯
啟動命令行工具,由於我裝的是VS2013,設置環境變量:
set DEPOT_TOOLS_WIN_TOOLCHAIN=0 ; 不設置這個會自動去下載sdksetup.exe
set GYP_MSVS_VERSION=2013
好了,現在最坑爹的問題來了,編譯提示:
src/tracing/trace-event.h(10): fatal error C1083: Cannot open include file: 'base/trace_event/common/trace_event_common.h': No such file or director
trace_event_common.h這個文件,無論是從鏡像還是google自身的托管倉庫都找不到。好吧,想辦法去找吧。
將文件放到\base\trace_event\common\trace_event_common.h后,重新編譯,
然后又會遇到下面的編譯警告,由於工程將警告視為錯誤,編譯不過:
warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
這是由於相關文件中含有unicode字符,刪除即可。
當目前為止,除測試用例相關的工程都應該可以編譯通過了。我這里編譯后\build\Debug\lib目錄下是這個樣子的: