我正在尝试遵循 Google V8 的基本“hello world”示例,如 here 所示。 。我使用的是 Ubuntu 13.10,gcc 版本 4.8.1;这应该很简单,不是吗?
构建 v8 本身并创建 hello world .cpp 文件后, 我运行(完全按照 Google 的建议**)
** 更新:好的,根据我对下面接受的答案的评论,我无意中没有完全按照谷歌的建议运行它,因为我认为文件名中的大括号是指示读者选择的指令一个选项,而不是一个 syntax that g++ would understand 。尽管如此,除了下面答案中建议的添加之外,它仍然不起作用
g++ -Iinclude helloworld.cpp -o hello_world out/x64.debug/obj.target/tools/gyp/libv8_base.x64.a -lpthread
并受到编译错误的轰炸。这里有太多的错误无法打印,但几乎所有错误都是以下形式:
undefined reference to 'icu_46 ...'
例如(一些示例行)
/home/ray/Playground/v8/out/../src/i18n.cc:138: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
/home/ray/Playground/v8/out/../src/i18n.cc:125: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
/home/ray/Playground/v8/out/../src/i18n.cc:147: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
经过多次谷歌搜索后,我发现这与 ICU 有关(请参阅 http://userguide.icu-project.org/howtouseicu ),但我不知道为什么会收到错误,以及我能做些什么。
虽然大多数错误与 icu_46 相关,但也有一些来自“bootstrapper.o”的错误:
/home/ray/Playground/v8/out/x64.debug/obj.target/v8_base.x64/src/bootstrapper.o: In function `v8::internal::Bootstrapper::NativesSourceLookup(int)':
/home/ray/Playground/v8/out/../src/bootstrapper.cc:77: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetBuiltinsCount()'
/home/ray/Playground/v8/out/../src/bootstrapper.cc:81: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetRawScriptSource(int)'
/home/ray/Playground/v8/out/x64.debug/obj.target/v8_base.x64/src/bootstrapper.o: In function `v8::internal::Genesis::CompileBuiltin(v8::internal::Isolate*, int)':
/home/ray/Playground/v8/out/../src/bootstrapper.cc:1448: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetScriptName(int)'
我不断地在谷歌上搜索这个问题,发现有迹象表明其他人也遇到了这个问题,但没有解决方案。任何帮助将不胜感激。谢谢。
最佳答案
我在 Ubuntu 12.04、g++ 4.6.3 和 v8 3.22.18 上遇到了同样的问题。 要成功编译 hello_world.cc,还需要添加 icu .a 库并链接到 rt 库。当您使用 make x64.debug 构建 v8 时,您完成的命令应该是:
g++ -Wall -Iinclude -o hello_world hello_world.cc ./out/x64.debug/obj.target/tools/gyp/libv8_{base.x64,snapshot}.a ./out/x64.debug/obj.target/third_party/icu/libicu{i18n,uc,data}.a -lrt
关于c++ - V8 "Hello World"示例 - 在 Ubuntu 13.10 上编译 - 大量 undefined reference 错误 "icu_46",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19602555/