我已经在Ubuntu 14.04上编译了V8,现在我正在努力让示例hello_world.cc正常工作,但是,当我执行它时,我得到了Segmentation fault (core dumped)
。
这是我的hello_world.cc来源:
#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);
return 0;
}
按照说明,这里是我用来将hello_world.cc构建成可执行文件的命令:
g++ -Iinclude -g hello_world.cc -o hello_world -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
请注意,除了说明之外,我还必须添加-lpthread
标志以使其编译,并-g
包含调试符号。
这是程序的输出:
$ ./hello_world
Segmentation fault (core dumped)
如果我跑gdb hello_world core
我得到:
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./hello_world'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000004148bb in v8::HandleScope::Initialize (this=0x7fff9b86a110, isolate=0x0) at ../src/api.cc:572
572 prev_next_ = current->next;
的第572行
答案 0 :(得分:2)
添加Isolate* isolate = Isolate::GetCurrent();
返回NULL
:
Isolate* isolate = Isolate::GetCurrent();
if(!isolate) {
isolate = v8::Isolate::New();
isolate->Enter();
}