我已经编译了V8在 Ubuntu 14.04 上,现在正在尝试获取示例 hello_world.cc但是,当我执行它时,我收到一个段错误(核心转储)
。
这是我的 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 行来自 src/api.cc is here
最佳答案
添加对 Isolate*isolate = Isolate::GetCurrent();
返回 NULL
的检查:
Isolate* isolate = Isolate::GetCurrent();
if(!isolate) {
isolate = v8::Isolate::New();
isolate->Enter();
}
关于c++ - 为什么 V8 的 Hello World 在 Ubuntu 上会导致段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23822761/