c++ - 为什么 V8 的 Hello World 在 Ubuntu 上会导致段错误?

标签 c++ ubuntu compiler-construction segmentation-fault v8

我已经编译了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/

相关文章:

java - JETTY服务器错误:404 on Ubuntu,地理服务器

java - 使用 Ant API 编译 Java 文件时出错 - "error starting modern compiler"

compiler-construction - 无法执行wfc386没有此类文件或目录-Watcom Fortran IDE

c++ - 是否有用于 C++/GTK 的 GUI 设计器?

c++ - 复制列 VectorXd 以便在 Eigen、C++ 中构造 MatrixXd

c++ - enable_if函数在不应该定义的时候定义

我程序中 cin.fail() 的 C++ 问题

python - 导入错误 : cannot import name _unquotepath

c - 如何编写一个从未知类型返回数值数组总和的函数?

c++ - 出现在错误列表中的 Visual C++ 的故意编译器警告?