一 编译V8
编译环境:
- 操作系统:windows 7
- CRT版本:vc90(vs2008)
- 编译工具:scons
- Python2.7
scons参数说明:
参数 | 默认 | 可选 | 说明 |
---|---|---|---|
library | static | shared | 指定编译的是静态库(lib)还是动态链接库(dll),默认为静态库(lib) |
snapshot | off | on | 是否启用snapshot,会优化启动速度(据说V8特有的JavaScript预编译功能是通过这个实现的),但编译出的文件会大160Kbytes+,默认不启用。 |
msvcrt | static | shared | 默认静态链接C++ Runtime Library(CRT) |
mode | release | debug | 大家应该都懂的 |
如果你想进一步确认,你可以查看V8/SConstruct文件:
编译步骤:
- 安装Python和Scons,并设置环境变量:(安装完成之后,应该已经为你设置好了)
将"C :/ Python25 ; C :/ Python25 / Scripts ;" (假定装在C盘,不包括双引号)加入到Path系统变量中
- 确定CRT(visual studio)版本:
E:/V8_Source>"C:/Program Files/Microsoft Visual Studio 9.0/VC/vcvarsall.bat"
然后通过参数env="PATH:%PATH%,INCLUDE:%INCLUDE%,LIB:%LIB%"传递给Scons
- 执行Scons (默认参数: library=static snapshot=off msvcrt=static mode=release)
E:/V8_Source> scons env="PATH:%PATH%,INCLUDE:%INCLUDE%,LIB:%LIB%"
10分钟左右之后,就会得到一个v8.lib(静态库,没有启用snapshot,静态链接CRT,release版本)
注意事项:
-
如果使用中文系统,可能会失败,得到如下错误:
profile-generator.cc
src/profile-generator.cc(936) : error C2220: warning treated as error - no 'object' file generated
src/profile-generator.cc(936) : 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
scons: *** [obj/release/profile-generator.obj] Error 2
scons: building terminated because of errors.
根据错误来看,很明显是因为字符编码问题;如果英文系统下将这个文件保存为Unicode编码文件,应该就可以在中文系统下编译了
windows7 支持多语言,只要装了英文语言包,再在区域和语言中将非Unicode字符的显示语言设置为英语就可以了
-
如果你想启用snapshot,就必须静态链接CRT(即使用默认参数msvcrt=static)。否则,你应该会得到如下错误:
(注意 :我没有找到相关确认资料,我只是描述我遇到的情况,如果你知道原因,请告诉我,谢谢! )
mksnapshot.cc
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/typeinfo(139) : error C2220: warning treated as error - no 'object' file generated
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/typeinfo(139) : warningC4275: non dll-interface class 'stdext::exception' used as base for dll-interfac
e class 'std::bad_cast'
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/exception(241) : see declaration of 'stdext::exception'
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/typeinfo(138) :see declaration of 'std::bad_cast'
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/typeinfo(160) : warningC4275: non dll-interface class 'stdext::exception' used as base for dll-interface class 'std::bad_typeid'
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/exception(241) : see declaration of 'stdext::exception'
C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE/typeinfo(159) :see declaration of 'std::bad_typeid'
scons: *** [obj/release/mksnapshot.obj] Error 2
scons: building terminated because of errors.
-
建议你为编译结果起一个好名字(动态库版本除外,最后会依赖v8.dll/v8_g.dll,所以不能改动名字)
不管你采用什么参数编译V8,最后只会得到:v8.lib v8_g.lib(debug)。这样很容易混乱,建议参照Boost库生成的命名规则,示例:
libV8-s-vc90-mtd(lib代表静态库,-s代表启用了snapshot,-mtd代表静态链接CRT的debug版本)