Google v8 - Hello world
OS:Window 7
1.下载v8 zip:https://github.com/v8/v8,解压zip,重命名v8-master文件夹为v8。
2.下载安装svn:http://tortoisesvn.net/downloads.html。安装后确认C:\Program Files\TortoiseSVN\bin被加到环境变量path
3.在v8根目录下Check out gyp
运行cmd:cd v8,切换到v8的根文件夹
运行cmd: svn co http://gyp.googlecode.com/svn/trunk build/gyp, gyp安装到v8/build/gyp
4.在v8根目录下Check out ICU
运行cmd:svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu46 third_party/icu
5.在v8根目录下Check out cygwin
运行cmd:svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@231940 third_party/cygwin
6.下载安装python 2.7.X:http://www.python.org/download/,安装后将python.exe的路径添加到path环境变量中
7.运行cmd:python build\gyp_v8 -Dtarget_arch=x64(注:按装python后要打开新的cmd窗口,并且当前目录切换到v8的根文件夹)
8.运行cmd:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\dev
env.exe" /build release build\all.sln,或者用VS2010打开v8\build\all.sln, build. Build成功后在v8\build\Release\lib生成v8_base.x64.lib,v8_nosnapshot.x64.lib,v8_snapshot.lib,icui18n.lib,icuuc.lib。
9.用VS2010创建一个c++ Win32 Console Application,添加x64 build配置。在linker里面导入v8_base.x64.lib,v8_nosnapshot.x64.lib,v8_snapshot.lib,icui18n.lib,icuuc.lib,ws2_32.lib,winmm.lib。
10.Copy/Paste以下代码到main函数
#include <v8.h> using namespace v8; int main(int argc, char* argv[]) { // Get the default Isolate created at startup. Isolate* isolate = Isolate::GetCurrent(); // Create a stack-allocated handle scope. HandleScope handle_scope(isolate); // Create a new context. Handle<Context> context = Context::New(isolate); // Enter the 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::NewFromUtf8(isolate, "'Hello' + ', World!'"); // Compile the source code. Handle<Script> script = Script::Compile(source); // Run the script to get the result. Handle<Value> result = script->Run(); // Convert the result to an UTF8 string and print it. String::Utf8Value utf8(result); printf("%s\n", *utf8); return 0; }
11.Build,如果出现以下linker error,添加msvcprtd.lib;MSVCRTD.lib到linker/input/Ignore Specific Default Libriries
>LIBCMT.lib(memcpy.obj) : error LNK2005: memmove already defined in MSVCRTD.lib(MSVCR100D.dll)
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步