【问题标题】:Linker error trying to embed v8尝试嵌入 v8 的链接器错误
【发布时间】:2014-10-28 00:17:38
【问题描述】:

我正在尝试制作一个嵌入 Google 的 V8 Javascript 引擎的简单程序。说明看起来很简单,但我遇到了一个奇怪的链接错误。

我在 Mac OS X 10.9 上,我使用 Xamarin Studio 作为我的 IDE,它似乎使用 g++ 作为编译器。

我使用 instructions on their site 编译了 v8。具体来说,毕竟make dependencies,我跑了:

make x64.release

这似乎成功完成。

这是我尝试构建项目时得到的输出:

g++ -o "/Users/mike/Projects/vate/vate/bin/Debug/vate" "/Users/mike/Projects/vate/vate/bin/Debug/hello_world.o" -v -L"/Users/mike /Projects/v8/xcodebuild/Debug" -l"icudata" -l"icui18n" -l"v8_snapshot" -l"icuuc" -l"v8_libbase" -l"v8_base" -l"v8_libplatform" Apple LLVM 5.1 版(clang-503.0.40)(基于 LLVM 3.4svn) 目标:x86_64-apple-darwin13.3.0 线程模型:posix “/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld”-demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o /Users/mike/Projects/vate/vate/bin /Debug/vate -L/Users/mike/Projects/v8/xcodebuild/Debug /Users/mike/Projects/vate/vate/bin/Debug/hello_world.o -licudata -licui18n -lv8_snapshot -licuuc -lv8_libbase -lv8_base -lv8_libplatform -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a 架构 x86_64 的未定义符号: “std::string::c_str() const”,引用自: v8::internal::Logger::SharedLibraryEvent(std::string const&, unsigned long, unsigned long) 在 libv8_base.a(log.o) “std::allocator::allocator()”,引用自: libv8_libbase.a(platform-macos.o) 中的 v8::base::OS::GetSharedLibraryAddresses() “std::allocator::~allocator()”,引用自: libv8_libbase.a(platform-macos.o) 中的 v8::base::OS::GetSharedLibraryAddresses() “std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)”,引用自: libv8_libbase.a(platform-macos.o) 中的 v8::base::OS::GetSharedLibraryAddresses() “std::basic_string, std::allocator >::basic_string(std::string const&)”,引用自: v8::base::OS::SharedLibraryAddress::SharedLibraryAddress(v8::base::OS::SharedLibraryAddress const&) 在 libv8_libbase.a(platform-macos.o) v8::base::OS::SharedLibraryAddress::SharedLibraryAddress(std::string const&, unsigned long, unsigned long) 在 libv8_libbase.a(platform-macos.o) “std::basic_string, std::allocator >::~basic_string()”,引用自: v8::base::OS::SharedLibraryAddress::~SharedLibraryAddress() 在 libv8_base.a(log.o) libv8_libbase.a(platform-macos.o) 中的 v8::base::OS::GetSharedLibraryAddresses() v8::base::OS::SharedLibraryAddress::~SharedLibraryAddress() 在 libv8_libbase.a(platform-macos.o) “std::string::operator=(std::string const&)”,引用自: v8::base::OS::SharedLibraryAddress::operator=(v8::base::OS::SharedLibraryAddress const&) 在 libv8_libbase.a(platform-macos.o) “std::_Rb_tree_decrement(std::_Rb_tree_node_base*)”,引用自: std::_Rb_tree_iterator >::operator--() 在 libv8_base.a(allocation-tracker.o) std::_Rb_tree_iterator >::operator--() 在 libv8_base.a(lithium-codegen.o) std::_Rb_tree_iterator::operator--() 在 libv8_base.a(verifier.o) std::_Rb_tree_iterator::operator--() 在 libv8_base.a(instruction.o) std::_Rb_tree_iterator >::operator--() in libv8_base.a(instruction-selector.o) std::_Rb_tree_iterator::operator--() 在 libv8_base.a(typer.o) std::_Rb_tree_iterator::operator--() 在 libv8_base.a(graph-visualizer.o) ... “std::_Rb_tree_increment(std::_Rb_tree_node_base const*)”,引用自: libv8_base.a(lithium.o) 中的 std::_Rb_tree_const_iterator >::operator++() std::_Rb_tree_const_iterator::operator++() 在 libv8_base.a(verifier.o) std::_Rb_tree_const_iterator >::operator++() in libv8_base.a(instruction.o) libv8_base.a(typer.o) 中的 std::_Rb_tree_const_iterator::operator++() libv8_base.a(graph-visualizer.o) 中的 std::_Rb_tree_const_iterator::operator++() “std::_Rb_tree_increment(std::_Rb_tree_node_base*)”,引用自: std::_Rb_tree_iterator >::operator++() 在 libv8_base.a(allocation-tracker.o) std::_Rb_tree_iterator >::operator++(int) in libv8_base.a(allocation-tracker.o) “std::__throw_length_error(char const*)”,引用自: std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::base::OS::SharedLibraryAddress const&) 在 libv8_libbase.a(platform-macos.o) std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator >>, v8::internal::compiler::Reducer* const&) 在 libv8_base.a(pipeline.o) std::vector >::_M_fill_insert(__gnu_cxx::__normal_iterator >>, unsigned long, v8::internal::compiler::Node* const&) 在 libv8_base.a(ast-graph-builder.o) std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::internal::compiler::Node* const&) 在 libv8_base.a(ast-graph-builder.o) std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator >>, v8::internal::compiler::FrameStateDescriptor* const&) 在 libv8_base.a(instruction.o) std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator >, v8::internal::compiler::Node* const&) 在 libv8_base.a(simplified-lowering.o) std::vector >::reserve(unsigned long) 在 libv8_base.a(instruction-selector.o) ... “std::__throw_out_of_range(char const*)”,引用自: std::vector >::_M_range_check(unsigned long) const in libv8_base.a(graph-reducer.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(ast-graph-builder.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(verifier.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(verifier.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(graph-replay.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(js-context-specialization.o) std::vector >::_M_range_check(unsigned long) const in libv8_base.a(graph-builder.o) ... “std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)”,引用自: libv8_base.a(allocation-tracker.o) 中的 std::_Rb_tree, std::_Select1st >, std::less, std::allocator >::erase(std::_Rb_tree_iterator >) “std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)”,引用自: std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair const&) 在 libv8_base.a(allocation -tracker.o) std::_Rb_tree, v8::internal::Handle, std::_Identity >, std::less >, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, v8::internal::Handle const&) 在 libv8_base.a(lithium-codegen.o) std::_Rb_tree, std::less, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, v8::internal::compiler::Node* const&) 在 libv8_base 中。一个(验证者.o) std::_Rb_tree, std::less, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, int const&) 在 libv8_base.a(instruction.o) std::_Rb_tree, std::_Select1st >, std::less, v8::internal::zone_allocator > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair const&) 在 libv8_base 中。 a(指令选择器.o) std::_Rb_tree, std::less, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, v8::internal::compiler::Node* const&) 在 libv8_base 中。一个(打字机.o) std::_Rb_tree, std::less, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, v8::internal::compiler::Node* const&) 在 libv8_base 中。一个(图形可视化器.o) ... ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

我感觉我编译了 v8 错误,或者可能是针对不同的编译器,但我找不到任何自定义方法。有没有其他人看过这个?

【问题讨论】:

  • 似乎g++ 程序告诉您它是基于 LLVM 并链接 libclang_rt。这可能是造成混淆的原因,因为缺少部分标准库。
  • 我刚刚意识到(由stackoverflow.com/questions/19557614/set-up-g-on-os-x 提供)OSX 上的 g++ 实际上不是 g++,而实际上是 clang++。嗯,我不确定是否更容易尝试在这里获得实际的 g++,或者尝试使其与 clang 一起工作......
  • 使用您链接的页面上的说明使用 clang 进行编译 - 让我们知道它是如何进行的。顺便说一句,clang 在启动时会立即通知您:Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  • @MichaelFoukarakis 直到今天我什至不知道什么是 clang 或 LLVM 或任何东西。我主要做 iOS 和 windows 开发,所以我对原生非 windows 开发有点陌生。无论如何,我会试一试。随意发布这个作为答案,如果它有效,我会接受它!
  • 嗯,我只是尝试按照这些说明进行操作,但似乎没有任何区别...我什至尝试了 xcode 说明,并将我的项目移动到 xcode 中,但我仍然得到相同的结果错误:(

标签: c++ clang v8 embedded-v8


【解决方案1】:

我想通了。我有两个问题:

  1. 我对自己实际使用的编译器感到困惑。在 OSX 上,g++ 实际上与 clang++ 符号链接,所以我需要使用 Clang 约定编译 V8,而不是 g++

  2. Google 页面上关于使用 clang 编译的说明不正确,根据此错误:https://code.google.com/p/v8/issues/detail?id=3072

作为参考,用clang编译,你需要像这样配置你的环境:

export CXX=`哪个clang++` 出口 CC=`哪个铿锵声` export CPP="`which clang` -E -std=c++11 -stdlib=libc++" export LINK="`which clang++` -std=c++11 -stdlib=libc++" export CXX_host=`哪个clang++` 出口 CC_host=`哪个铿锵声` 导出 CPP_host="`which clang` -E" export LINK_host=`哪个clang++` 导出 GYP_DEFINES="clang=1 mac_deployment_target=10.9"

然后您可以正常运行make whatever 命令。

显然,需要安装 xcode 以便存在 clang 和 clang++。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2020-02-23
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多