【发布时间】:2014-05-23 09:02:06
【问题描述】:
我已经在 Ubuntu 上编译了V8,并且有一个非常简单的 V8 程序,叫做isolate_test.cc。它基于Hello World example from Google:
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
V8::initialize();
Isolate* isolate = Isolate::GetCurrent(); //Always returns NULL
return 0;
}
我用来编译这个程序的命令是:
g++ -Iinclude -g isolate_test.cc -o isolate_test -Wl,--start-group out/x64.debug/obj.target/{tools/gyp/libv8_{base,snapshot},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -lpthread
问题是Isolate::GetCurrent() 总是返回NULL。为什么会发生这种情况,获取当前Isolate 的正确方法是什么?
我可能会偏离轨道,但我的第一个想法是这与 Isolate::GetCurrent() 无法从 libpthread 获取当前线程有关。
更新:根据this question,我已将V8::initialize() 添加为程序中的第一个调用,但这并不能解决问题。
【问题讨论】:
-
见 stackoverflow.com/questions/16924087/… ,你可能错过了对 V8::initialize(); 的调用,这可能也是示例中的文档错误
-
我找不到任何对
V8::initialize()的引用 - 它是否已从 API 中删除? -
不完全确定,虽然它是在您指向Isolate::GetCurrent()的链接文件中定义的