如何在Mac上安装therubyracer? “宝石安装therubyracer -v”无法正常工作

时间:2020-06-16 16:18:15

标签: ruby-on-rails ruby rubygems therubyracer

我一直在尝试安装therubyracer,并尝试了我在stackoverflow上可以找到的几乎所有方法,但它似乎仍然给我同样的错误。我也是红宝石的新手,所以我无法准确浏览错误消息。下面是错误消息:

ERROR:  Error installing therubyracer:
        ERROR: Failed to build gem native extension.

    current directory: /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8
/Users/zoepa/.rvm/rubies/ruby-2.7.0/bin/ruby -I /Users/zoepa/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0 -r ./siteconf20200616-2984-xp1oct.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8@3.15
creating Makefile
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-building-tests.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-werror-on-osx.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-xcode-debugging.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-imply-vfp3-and-armv7.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-use-MAP_NORESERVE-on-freebsd.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-use-vfp2.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/fPIC-for-static.patch
Compiling v8 for x64
Using python 2.7.16
Using compiler: c++ (clang version 11.0.0)
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=c++ LINK=c++  /usr/bin/make x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
        build/gyp/gyp --generator-output="out" build/all.gyp \
                      -Ibuild/standalone.gypi --depth=. \
                      -Dv8_target_arch=x64 \
                      -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  CXX(target) /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../src/allocation.cc:33:
../src/utils.h:33:10: fatal error: 'climits' file not found
#include <climits>
         ^~~~~~~~~
1 warning and 1 error generated.
make[1]: *** [/Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o] Error 1
make: *** [x64.release] Error 2
/Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
        from /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `each'
        from /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `verify_installation!'
        from /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:26:in `install!'
        from extconf.rb:7:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19 for inspection.
Results logged to /Users/zoepa/.rvm/gems/ruby-2.7.0/extensions/x86_64-darwin-19/2.7.0/libv8-3.16.14.19/gem_make.out

2 个答案:

答案 0 :(得分:2)

如错误消息所述,您正在使用Clang,但是您安装的libv8的过时版本仅支持GCC。

请注意,therubyracer的最新版本是从2017年1月开始的(自2013年初以来似乎没有任何进展),它使用的libv8的版本也是如此(当然,附带的V8的版本也是如此)该版本的libv8)。建议从2012年开始使用GCC 4.4。

我怀疑您是否会支持libv8,V8或GCC这样的旧版本。另外,请注意,当时还没有Ruby 2.7,2017年初的Ruby当前版本是2.4,2013年初是2.0。

答案 1 :(得分:0)

您可能没有 v8 的系统版本,您可以执行以下操作:

env \
  CXX=clang++ \
  GYPFLAGS=-Dmac_deployment_target=10.9 \
gem install libv8 --version 3.16.14.19

这假设您在 Mac 上有典型的开发人员设置——安装了命令行工具的最新 Xcode。

原答案:https://github.com/rubyjs/libv8/issues/282#issuecomment-568538097

相关问题