1
votes

I am trying to make a simple program where I embed Google's V8 Javascript engine. The instructions seem straight forward, but I'm getting an odd link error.

I'm on Mac OS X 10.9, and I'm using Xamarin Studio as my IDE which appears to be using g++ as the compiler.

I compiled v8 using the instructions on their site. Specifically, after all the make dependencies, I ran:

make x64.release

This appeared to complete successfully.

Here's the output I'm getting when I try to build my project:

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 version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: 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
Undefined symbols for architecture x86_64:
  "std::string::c_str() const", referenced from:
      v8::internal::Logger::SharedLibraryEvent(std::string const&, unsigned long, unsigned long) in libv8_base.a(log.o)
  "std::allocator::allocator()", referenced from:
      v8::base::OS::GetSharedLibraryAddresses() in libv8_libbase.a(platform-macos.o)
  "std::allocator::~allocator()", referenced from:
      v8::base::OS::GetSharedLibraryAddresses() in libv8_libbase.a(platform-macos.o)
  "std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)", referenced from:
      v8::base::OS::GetSharedLibraryAddresses() in libv8_libbase.a(platform-macos.o)
  "std::basic_string, std::allocator >::basic_string(std::string const&)", referenced from:
      v8::base::OS::SharedLibraryAddress::SharedLibraryAddress(v8::base::OS::SharedLibraryAddress const&) in libv8_libbase.a(platform-macos.o)
      v8::base::OS::SharedLibraryAddress::SharedLibraryAddress(std::string const&, unsigned long, unsigned long) in libv8_libbase.a(platform-macos.o)
  "std::basic_string, std::allocator >::~basic_string()", referenced from:
      v8::base::OS::SharedLibraryAddress::~SharedLibraryAddress() in libv8_base.a(log.o)
      v8::base::OS::GetSharedLibraryAddresses() in libv8_libbase.a(platform-macos.o)
      v8::base::OS::SharedLibraryAddress::~SharedLibraryAddress() in libv8_libbase.a(platform-macos.o)
  "std::string::operator=(std::string const&)", referenced from:
      v8::base::OS::SharedLibraryAddress::operator=(v8::base::OS::SharedLibraryAddress const&) in libv8_libbase.a(platform-macos.o)
  "std::_Rb_tree_decrement(std::_Rb_tree_node_base*)", referenced from:
      std::_Rb_tree_iterator >::operator--() in libv8_base.a(allocation-tracker.o)
      std::_Rb_tree_iterator >::operator--() in libv8_base.a(lithium-codegen.o)
      std::_Rb_tree_iterator::operator--() in libv8_base.a(verifier.o)
      std::_Rb_tree_iterator::operator--() in libv8_base.a(instruction.o)
      std::_Rb_tree_iterator >::operator--() in libv8_base.a(instruction-selector.o)
      std::_Rb_tree_iterator::operator--() in libv8_base.a(typer.o)
      std::_Rb_tree_iterator::operator--() in libv8_base.a(graph-visualizer.o)
      ...
  "std::_Rb_tree_increment(std::_Rb_tree_node_base const*)", referenced from:
      std::_Rb_tree_const_iterator >::operator++() in libv8_base.a(lithium.o)
      std::_Rb_tree_const_iterator::operator++() in libv8_base.a(verifier.o)
      std::_Rb_tree_const_iterator >::operator++() in libv8_base.a(instruction.o)
      std::_Rb_tree_const_iterator::operator++() in libv8_base.a(typer.o)
      std::_Rb_tree_const_iterator::operator++() in libv8_base.a(graph-visualizer.o)
  "std::_Rb_tree_increment(std::_Rb_tree_node_base*)", referenced from:
      std::_Rb_tree_iterator >::operator++() in 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*)", referenced from:
      std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::base::OS::SharedLibraryAddress const&) in libv8_libbase.a(platform-macos.o)
      std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::internal::compiler::Reducer* const&) in libv8_base.a(pipeline.o)
      std::vector >::_M_fill_insert(__gnu_cxx::__normal_iterator > >, unsigned long, v8::internal::compiler::Node* const&) in libv8_base.a(ast-graph-builder.o)
      std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::internal::compiler::Node* const&) in libv8_base.a(ast-graph-builder.o)
      std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::internal::compiler::FrameStateDescriptor* const&) in libv8_base.a(instruction.o)
      std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, v8::internal::compiler::Node* const&) in libv8_base.a(simplified-lowering.o)
      std::vector >::reserve(unsigned long) in libv8_base.a(instruction-selector.o)
      ...
  "std::__throw_out_of_range(char const*)", referenced from:
      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&)", referenced from:
      std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::erase(std::_Rb_tree_iterator >) in libv8_base.a(allocation-tracker.o)
  "std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
      std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair const&) in 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&) in 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&) in libv8_base.a(verifier.o)
      std::_Rb_tree, std::less, v8::internal::zone_allocator >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, int const&) in 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&) in libv8_base.a(instruction-selector.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&) in libv8_base.a(typer.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&) in libv8_base.a(graph-visualizer.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have a feeling that I compiled v8 wrong, or perhaps for a different compiler, but I can't find any way to customize that. Has anyone else seen this?

1
It seems the program g++ tells you it's LLVM based and links libclang_rt. This might be a possible source of confusion, since parts of std lib are missing.erenon
I just realized (courtesy of stackoverflow.com/questions/19557614/set-up-g-on-os-x) that g++ on OSX is not actually g++, but is actually clang++. Hm, I'm not sure whether it would be easier to try and get actual g++ on here, or to try and make it work with clang...Mike Caron
Use the instructions on the page you linked to compile with clang - let us know how it goes. BTW, clang informs you about itself right when it starts: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)Michael Foukarakis
@MichaelFoukarakis I didn't even know what clang or LLVM or anything was until today. I primarily do iOS and windows development, so I'm kind of new to native non-windows development. Anyway, I'll give it a shot. Feel free to post this as an answer, and if it works, I'll accept it!Mike Caron
Hm, I just tried following those instructions, and it didn't seem to make any difference... I even tried the xcode instructions, and moving my project into xcode, and I still get the same errors :(Mike Caron

1 Answers

3
votes

I have figured it out. I had two problems:

  1. I was confused about which compiler I was actually using. On OSX, g++ is actually symlinked to clang++, so I needed to compile V8 using the Clang conventions, not g++

  2. The instructions on compiling with clang on Google's page are incorrect, per this bug: https://code.google.com/p/v8/issues/detail?id=3072

For reference, to compile with clang, you need to configure your environment like this:

export CXX=`which clang++`
export CC=`which clang`
export CPP="`which clang` -E -std=c++11 -stdlib=libc++"
export LINK="`which clang++` -std=c++11 -stdlib=libc++"
export CXX_host=`which clang++`
export CC_host=`which clang`
export CPP_host="`which clang` -E"
export LINK_host=`which clang++`
export GYP_DEFINES="clang=1 mac_deployment_target=10.9"

You can then run your make whatever command as normal.

Obviously, requires that xcode be installed so that clang and clang++ exist.