安装 therubyracer 0.11.4 版本的 gem?

10

我几乎疯了,要安装therubyracer。我知道有很多人和我一样遇到了相同的问题,我也看过这些问题,但是因为不同的情况有不同的解决方案,所以对我来说太复杂了。实际上,并没有一个好的方法来解决这个问题。我的问题类似于这个,并且有讨论,但是仍然没有结论。

尽管如此,Chris S提出的这个问题是一个很好的问题,但结果并不好。

①以下是关于我的问题的一些注释:

1. ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin15]

2. libv8 3.11.8.17 with native extensions

②操作系统版本是OS X El Capitan, 10.11

③以下是错误信息:

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

/Users/hufeipeng/.rbenv/versions/2.2.1/bin/ruby -r ./siteconf20151026-41811-14t2l9a.rb extconf.rb

checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling accessor.cc
clang: warning: argument unused during compilation: '-rdynamic'
In file included from accessor.cc:1:
In file included from ./rr.h:4:
/usr/local/include/v8.h:353:33: error: use of undeclared identifier 'nullptr'
V8_INLINE MaybeLocal() : val_(nullptr) {}
                            ^
/usr/local/include/v8.h:360:51: error: use of undeclared identifier 'nullptr'
V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
                                              ^
/usr/local/include/v8.h:364:29: error: use of undeclared identifier 'nullptr'
out->val_ = IsEmpty() ? nullptr : this->val_;
                        ^
/usr/local/include/v8.h:430:50: error: use of undeclared identifier 'nullptr'
bool IsFirstPass() const { return callback_ != nullptr; }
                                             ^
/usr/local/include/v8.h:790:42: error: use of undeclared identifier 'nullptr'
V8_INLINE Global() : PersistentBase<T>(nullptr) {}
                                     ^
/usr/local/include/v8.h:815:18: error: use of undeclared identifier 'nullptr'
other.val_ = nullptr;
             ^
/usr/local/include/v8.h:827:18: error: use of undeclared identifier 'nullptr'
rhs.val_ = nullptr;
             ^
/usr/local/include/v8.h:1092:52: error: use of undeclared identifier 'nullptr'
ScriptOrigin* origin = nullptr));
                         ^
/usr/local/include/v8config.h:347:48: note: expanded from macro 'V8_DEPRECATE_SOON'
#define V8_DEPRECATE_SOON(message, declarator) declarator
                                           ^
In file included from accessor.cc:1:
In file included from ./rr.h:4:
/usr/local/include/v8.h:1095:30: error: use of undeclared identifier 'nullptr'
ScriptOrigin* origin = nullptr);
                         ^
/usr/local/include/v8.h:2283:42: error: 'v8::NewStringType' is not a class, namespace, or scoped enumeration
kNormalString = static_cast<int>(v8::NewStringType::kNormal),
                                     ^
/usr/local/include/v8.h:2284:48: error: 'v8::NewStringType' is not a class, namespace, or scoped enumeration
kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
                                           ^
/usr/local/include/v8.h:3205:36: error: use of undeclared identifier 'nullptr'
return NewInstance(context, 0, nullptr);
                               ^
/usr/local/include/v8.h:3434:38: error: 'v8::ArrayBufferCreationMode' is not a class, namespace, or scoped enumeration
ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
                                 ^
/usr/local/include/v8.h:3797:38: error: 'v8::ArrayBufferCreationMode' is not a class, namespace, or scoped enumeration
ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
                                 ^
/usr/local/include/v8.h:4457:36: error: 'v8::PropertyHandlerFlags' is not a class, namespace, or scoped enumeration
PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
                             ^
/usr/local/include/v8.h:4485:36: error: 'v8::PropertyHandlerFlags' is not a class, namespace, or scoped enumeration
PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
                             ^
/usr/local/include/v8.h:7151:27: error: use of undeclared identifier 'nullptr'
if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
                        ^
/usr/local/include/v8config.h:353:54: note: expanded from macro 'V8_UNLIKELY'
# define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
                                                 ^
In file included from accessor.cc:1:
In file included from ./rr.h:4:
/usr/local/include/v8.h:7596:46: error: 'v8::NewStringType' is not a class, namespace, or scoped enumeration
Set(v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
                                         ^
In file included from accessor.cc:1:
./rr.h:358:39: error: no member named 'ScriptData' in namespace 'v8'
class ScriptData : public Pointer<v8::ScriptData> {
                              ~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [accessor.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/Users/*/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/therubyracer-0.11.4 for inspection.
Results logged to
/Users/*/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/therubyracer-0.11.4/gem_make.out

救命啊!



首先,非常抱歉重新编辑这个问题,太忙了没有时间留意你们回复的评论。在此,我非常感谢@Javid Jamae为我提供了一个非常好的解决问题的方法,尽管还有一些小问题需要处理,但只要我们需要错误来帮助我们找到最终答案就可以了。下面是我尝试了@Javid Jamae的方法后的控制台输出:

首先,我之前没有使用brew安装gcc,因此我用brew安装了它,版本是最新的5.2.0/usr/local/Cellar/gcc/5.2.0)。以下是详细信息:

➜  /Users/xxx  >brew install gcc
==> Installing dependencies for gcc: gmp, mpfr, libmpc, isl
==> Installing gcc dependency: gmp
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.0.0a.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gmp-6.0.0a.el_capitan.bottle.tar.gz
  /usr/local/Cellar/gmp/6.0.0a: 15 files, 3.2M
==> Installing gcc dependency: mpfr
==> Downloading https://homebrew.bintray.com/bottles/mpfr-3.1.3.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mpfr-3.1.3.el_capitan.bottle.tar.gz
  /usr/local/Cellar/mpfr/3.1.3: 24 files, 3.6M
==> Installing gcc dependency: libmpc
==> Downloading https://homebrew.bintray.com/bottles/libmpc-1.0.3.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libmpc-1.0.3.el_capitan.bottle.tar.gz
  /usr/local/Cellar/libmpc/1.0.3: 10 files, 380K
==> Installing gcc dependency: isl
==> Downloading https://homebrew.bintray.com/bottles/isl-0.14.1.el_capitan.bottle.3.tar.gz
######################################################################## 100.0%
==> Pouring isl-0.14.1.el_capitan.bottle.3.tar.gz
  /usr/local/Cellar/isl/0.14.1: 68 files, 3.2M
==> Installing gcc
==> Downloading https://homebrew.bintray.com/bottles/gcc-5.2.0.el_capitan.bottle.2.tar.gz
##################### 29.8%
curl: (56) SSLRead() return error -9806
Error: Failed to download resource "gcc"
Download failed: https://homebrew.bintray.com/bottles/gcc-5.2.0.el_capitan.bottle.2.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading http://ftpmirror.gnu.org/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2
==> Downloading from http://mirrors.ustc.edu.cn/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2
######################################################################## 100.0%
==> Patching
patching file gcc/jit/Make-lang.in
patching file gcc/jit/jit-playback.c
Hunk #1 succeeded at 2459 with fuzz 2 (offset 43 lines).
==> ../configure --build=x86_64-apple-darwin15.0.0 --prefix=/usr/local/Cellar/gcc/5.2.0 --libdir=/usr/local/Cel
==> make bootstrap
==> make install
==> Caveats
GCC has been built with multilib support. Notably, OpenMP may not work:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to brew reinstall gcc --without-multilib
==> Summary
  /usr/local/Cellar/gcc/5.2.0: 1353 files, 248M, built in 52.4 minutes

看起来安装已经没问题了! 然后,我用 gem 卸载了 therubyracerlibv8。然而,当我要安装 therubyracer 时(没有指定版本,在安装或者 Gemfile 中),bundle 提醒我需要版本 0.12.2,就出现了错误:

➜  /Users/xxx/Documents/workspace/xxx git:(master) ✗ >gem install therubyracer -v '0.12.2'
Fetching: libv8-3.16.14.13.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
ERROR: Failed to build gem native extension.
/Users/xxx/.rbenv/versions/2.2.1/bin/ruby -r ./siteconf20151230-50968-1yqguip.rb extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.10
Using compiler: /usr/bin/c++ (clang version 6.1.0)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file:
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o has no symbols
In file included from ../src/accessors.cc:28:
In file included from ../src/v8.h:60:
In file included from ../src/objects-inl.h:38:
In file included from ../src/elements.h:33:
In file included from ../src/heap.h:35:
In file included from ../src/incremental-marking.h:33:
In file included from ../src/mark-compact.h:32:
../src/spaces.h:896:26: error: 'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to true [-Werror,-Wtautological-undefined-compare]
bool exists() { return this != NULL && code_range_ != NULL; }
                     ^~~~    ~~~~
../src/spaces.h:898:9: error: 'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false [-Werror,-Wtautological-undefined-compare]
if (this == NULL || code_range_ == NULL) return false;
    ^~~~    ~~~~
2 errors generated.
make[1]: ***
[/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/vendor/v8/out/x64.release/obj.target/v8_base/src/accessors.o]
Error 1
make: *** [x64.release] Error 2
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/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/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/ext/libv8/location.rb:35:in `each'
from
/Uses/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/ext/libv8/location.rb:35:in `verify_installation!'
from
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/ext/libv8/location.rb:26:in `install!'
from extconf.rb:7:in `<main>'
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/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
CXX(target)
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o
CXX(target)
/Users/xxx/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/libv8-3.16.14.13/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o
.................. (the follow error messages are similar to above)

我猜想问题仍与libv8有关! 起初,我认为可能是therubyracer版本的问题,因此我尝试安装版本0.12.0,但不幸的是,出现了相同的错误。 有些奇怪,我的意思是,在我的情况下,libv8therubyracer一起安装(从错误消息中可以看出),但你和我不同。 根据您的建议,您在安装therubyracer之后安装了libv8,为什么它们不同呢? 可能与我的ruby环境设置有关,这里是我发布的Gemfile配置:

gem 'rails', '4.1.6'
gem 'mysql2', '0.3.18'
gem 'sass-rails', '~> 4.0.3'
gem 'bootstrap-sass', '~> 3.3.4'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'

gem 'therubyracer', platforms: :ruby

gem 'jquery-rails','3.1.2'
gem 'jquery-ui-rails', '4.0.5'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'log4r', '1.1.9'
gem 'devise','3.4.1'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.6.0'
gem 'thin','1.6.2'
gem 'kaminari', '0.16.1'
gem 'factory_girl_rails'
gem 'httparty'
gem "select2-rails",'3.5.9.3'

group :test, :development do
    gem 'net-ssh', '2.7.0'
    gem 'capistrano', '2.12.0'
    gem 'capistrano-rbenv', '1.0.1'
    gem 'spring'
    gem 'magic_encoding', '0.0.2'
    gem 'rspec-rails', '3.2.0'
end

你解决了这个问题吗??我也遇到了同样的问题,真是让人抓狂。 - trevorhinesley
@frank-jorsn - 我看到了你对我的回答编辑的评论(被拒绝了)。你说gcc安装成功了,但是如果你再看一下输出,你会发现它并没有成功:'Error: Failed to download resource "gcc"'. 我对此不是很清楚,但请确保gcc已经正确安装,我认为我的解决方案会对你有帮助。祝你好运! - Javid Jamae
@Javid Jamae,非常抱歉现在才回复您的评论。我在公司的一个项目中非常忙碌,很长时间没有注意到StackOverflow的通知。我已经阅读了您的评论,您在评论中提醒的gcc安装问题并不完全正确。我确实以正确的方式安装了gcc,在您的编辑中复制的响应中从未说过安装gcc失败,只是下载资源失败,但尝试另一个资源成功了。这些可以在最后一个响应控制台内容中检查,恐怕您丢失了细节。我将再次为您复制控制台内容如下! - frank jorsn
@Javid Jamae 第一次控制台: ==> 正在下载 https://homebrew.bintray.com/bottles/gcc-5.2.0.el_capitan.bottle.2.tar.gz ##################### 29.8% curl: (56) SSLRead() 返回错误 -9806 错误:无法下载资源“gcc” 下载失败:https://homebrew.bintray.com/bottles/gcc-5.2.0.el_capitan.bottle.2.tar.gz 警告:瓶装安装失败:从源代码构建。 第二次控制台: ==> 正在下载 http://ftpmirror.gnu.org/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2 ==> 从 http://mirrors.ustc.edu.cn/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2 下载成功! - frank jorsn
@ Javid Jamae 这是用于获取gcc版本信息的控制台命令:brew upgrade gcc 错误:gcc 5.2.0已经安装。 - frank jorsn
3个回答

12

这对我起作用:

$ brew upgrade gcc

$ gem uninstall therubyracer

$ gem uninstall libv8

$ gem install therubyracer -v '0.12.0'
Fetching: therubyracer-0.12.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed therubyracer-0.12.0
1 gem installed

$ gem install libv8 -v '3.16.14.3' -- --with-system-v8
Fetching: libv8-3.16.14.3.gem (100%)
Building native extensions with: '--with-system-v8'
This could take a while...
Successfully installed libv8-3.16.14.3
1 gem installed

参考资料:


1
同意。经过很多努力,这对我有用! - don.najd
1
第三个。在这个帖子和许多其他帖子中,我尝试了十几种解决方案,直到最后这个终于起作用了。实际上,我不得不执行:`$ brew install gcc`... 它花了35分钟才完成,但是然后 therubyracer 终于成功被安装了。 - Greg Charles

9

我在OSX El Capitan中也遇到了同样的问题。我采用以下步骤解决了这个问题:

首先检查V8是否安装。我使用brew进行安装。

brew install homebrew/versions/v8-315

尝试卸载libv8和therubyracer宝石(如果存在)来解决问题。
gem uninstall -a libv8
gem uninstall -a therubyracer

然后安装libv8 gem。
gem install libv8 -v '<<VERSION>>' -- --with-system-v8

然后安装therubyracer宝石。

gem install therubyracer -v '<<VERSION>>' -- --with-v8-dir=$(brew --prefix v8-315)

非常感激和兴奋,关于依赖于libv8v8therubyracer的问题终于解决了!@Pranshu Verma,你真的帮了我很多,让我了解了这三者之间的关系。我会根据自己的理解对此做出总结,再次感谢你。 - frank jorsn
它对我有用,我省略了“-v <<VERSION>>”参数。 - Holger Frohloff

0

我曾经遇到过同样的问题,将therubyracer更新到最新版本后问题得以解决。

尝试:

bundle update therubyracer

如果您也遇到了libv8的问题,请尝试以下方法:
bundle update libv8

嗨,@user1894919!也许你的解决方案是解决therubyracer和"libv8"版本问题的好方法,但它不能解决我的问题。你应该知道我有安装therubyracer的问题,这意味着我从未在我的计算机上安装过therubyracer,所以更新的方式对我来说不是一个好主意。以下是错误信息:**$bundle update therubyracer** -> 此Bundle尚未安装。运行bundle install以更新和安装捆绑的gems。无论如何,还是谢谢! - frank jorsn
嗨 @frankjorsn,在这种情况下,请尝试编辑Gemfile以使用最新版本的therubyracer和libv8(如果需要)​​,然后运行bundle install,这可能适用于您。抱歉耽搁了,我现在才看到您的回复。 - user1894919

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接