Ubuntu下v8 javascript虚拟机的编译与使用
2015-01-08 14:37
239 查看
v8 developer官方主页:https://developers.google.com/v8/
v8 代码下载和编译官方主页:https://developers.google.com/v8/build
其实这里面对代码的下载和编译的相关内容已经比较详细了,但是这也意味着并不完整,简而言之我按着他的步骤编译不出来,如下是我的具体步骤(红色部分为非官方提供的步骤):
1.下载源代码:svn checkout http://v8.googlecode.com/svn/trunk/ v8
2.安装depot_tools(用来管理代码和审查以及得到gclient目录):
2.1 svn
co http://src.chromium.org/svn/trunk/tools/depot_tools2
2.2 设置环境变量:$ export PATH=`pwd`/depot_tools:"$PATH"
3.make dependencies获取各种make需要的依赖
4.make
ia32.release
或者 make ia32.release library=shared
5.编译例子:
例子基本是v8官网已经很详细了:https://developers.google.com/v8/get_started
首先创建一个.cc源文件:
编译的命令:
g++
-I. hello_world.cc -o hello_world -Wl,--start-group out/x64.release/obj.target/{tools/gyp/libv8_{base,libbase,snapshot,libplatform},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -pthread
执行:
./hello_world
v8 代码下载和编译官方主页:https://developers.google.com/v8/build
其实这里面对代码的下载和编译的相关内容已经比较详细了,但是这也意味着并不完整,简而言之我按着他的步骤编译不出来,如下是我的具体步骤(红色部分为非官方提供的步骤):
1.下载源代码:svn checkout http://v8.googlecode.com/svn/trunk/ v8
2.安装depot_tools(用来管理代码和审查以及得到gclient目录):
2.1 svn
co http://src.chromium.org/svn/trunk/tools/depot_tools2
2.2 设置环境变量:$ export PATH=`pwd`/depot_tools:"$PATH"
3.make dependencies获取各种make需要的依赖
4.make
ia32.release
或者 make ia32.release library=shared
5.编译例子:
例子基本是v8官网已经很详细了:https://developers.google.com/v8/get_started
首先创建一个.cc源文件:
#include "include/v8.h" #include "include/libplatform/libplatform.h" using namespace v8; int main(int argc, char* argv[]) { // Initialize V8. V8::InitializeICU(); Platform* platform = platform::CreateDefaultPlatform(); V8::InitializePlatform(platform); V8::Initialize(); // Create a new Isolate and make it the current one. Isolate* isolate = Isolate::New(); { Isolate::Scope isolate_scope(isolate); // Create a stack-allocated handle scope. HandleScope handle_scope(isolate); // Create a new context. Local<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. Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); // Compile the source code. Local<Script> script = Script::Compile(source); // Run the script to get the result. Local<Value> result = script->Run(); // Convert the result to an UTF8 string and print it. String::Utf8Value utf8(result); printf("%s\n", *utf8); } // Dispose the isolate and tear down V8. isolate->Dispose(); V8::Dispose(); V8::ShutdownPlatform(); delete platform; return 0; }
编译的命令:
g++
-I. hello_world.cc -o hello_world -Wl,--start-group out/x64.release/obj.target/{tools/gyp/libv8_{base,libbase,snapshot,libplatform},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -pthread
执行:
./hello_world
相关文章推荐
- windows下使用VS2015编译V8 JavaScript引擎(v5.5 - 2016/09)
- 虚拟机搭载UBUNTU编译MicroPython,在STM32上面使用
- Window下使用虚拟机Ubuntu编译Ffmpeg(编译的只有arm平台下的)
- V8 JavaScript Engine 编译与使用注意事项-编译V8(win7+VS2008)
- 虚拟机ubuntu 使用adb 编译调试系统app Settings.apk
- V8 JavaScript Engine 编译与使用注意事项-使用V8
- Ubuntu 下使用Eclipse编译、调试嵌入式程序的方法(中)
- Ubuntu 下使用Eclipse编译、调试嵌入式程序的方法(下)
- ubuntu9.10使用第一天(教育网直通车+源修改+C++编译环境搭建+输入法安装)
- Ubuntu 使用emacs+auctex编译tex文档
- VMware 下复制ubuntu虚拟机到新服务器后导致虚拟机网卡无法使用
- Ubuntu下使用Eclipse编译、调试嵌入式程序的方法(上)
- ubuntu下编译和使用libxml2
- Ubuntu上ldid编译和使用
- Ubuntu(Linux)使用Eclipse搭建C/C++编译环境
- 第一次使用Ubuntu的Vim编写C,简单的gcc编译方法
- 虚拟机ubuntu下nfs配置,使用uboot nfs命令下载内核至mini2440
- Ubuntu 下用C语言访问gdbm数据库编译注意事项(使用ndbm方式)
- V8 JavaScript Engine编译与测试
- 图示虚拟机virtualbox在Ubuntu下的安装使用