therubyracer – Gem :: Ext :: BuildError:错误:无法构buildgem原生扩展

我正在尝试在小牛上安装以下的gem版本

  • libv8(3.16.14.3)
  • therubyracer(0.12.1)

显然therubyracergem取决于libv8。

1)安装libv8

什么是libv8? 我的一点研究似乎暗示它是Google Chrome使用的某种JavaScript库?

我在安装时遇到了麻烦,但是这个好post既有我的错误,也有关于如何绕过它的一个很好解释的答案。

所以我安装了libv8

 gem install libv8 -- --with-system-v8 

这是我的理解,这安装的gem,但使用我的本地系统安装的V8库,而不是…与版本的gem? 无论哪种方式,它都是成功的。

2)安装therubyracer

在下一步,我遇到了安装therubyracergem的麻烦。 我不太清楚这个gem是干什么的,只是这是一个我试图bundle install的rails项目的依赖项。

它给了我以下错误:

 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /Users/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb checking for main() in -lpthread... yes checking for main() in -lobjc... yes checking for v8.h... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/bin/ruby --with-pthreadlib --without-pthreadlib --with-objclib --without-objclib --enable-debug --disable-debug --with-v8-dir --without-v8-dir --with-v8-include --without-v8-include=${v8-dir}/include --with-v8-lib --without-v8-lib=${v8-dir}/lib /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/libv8-3.16.14.3/ext/libv8/location.rb:50:in 'configure': You have chosen to use the version of V8 found on your system (Libv8::Location::System::NotFoundError) and *not* the one that is bundled with the libv8 rubygem. However, it could not be located. please make sure you have a version of v8 that is compatible with 3.16.14.3 installed. You may need to special --with-v8-dir options if it is in a non-standard location thanks, The Mgmt from /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/libv8-3.16.14.3/lib/libv8.rb:7:in `configure_makefile' from extconf.rb:32:in `<main>' extconf failed, exit code 1 Gem files will remain installed in /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/therubyracer-0.12.1 for inspection. Results logged to /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/extensions/x86_64-darwin-13/1.9.1/therubyracer-0.12.1/gem_make.out 

从我可以收集的信息中,我select使用本地V8库来安装libv8而不是使用libv8提供的libv8 ,但现在无法find本地安装。

  • 我如何检查是否确实安装了V8,如何find它?
  • 我尝试了几个指定的标志,他们都没有把gem指向正确的安装目录
  • 这可能是一个单独的主题,但什么是extconf.rb ? 我在几个地方见过。 而在具体的gcc编译器试图做什么?

谢谢!!

编辑:

  1. 我尝试了这个解决scheme ,卸载libv8并通过brew install重新brew install 。 有几个类似的问题也提到过。 没有运气。

  2. 我也试过这里描述的CCCXXCPP环境variables,尽pipe我不认为这样做有任何作用,因为它已经拿起了我的gcc v4.6编译器。

这一步为我工作。

操作系统:特立独行的ruby:2.1.1

 gem uninstall libv8 gem install therubyracer -v '0.11.3' gem install libv8 -v '3.11.8.13' -- --with-system-v8 

对于那些在OS X El Capitan中遇到这个问题的人来说, 这个来自therubyracer issue thread的解决scheme终于为我工作了:

 brew tap homebrew/versions brew install v8-315 gem install libv8 -v '3.16.14.13' -- --with-system-v8 gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315 bundle install 

我之前也运行过brew install gcc ,但是我不确定这是否是必要的。

尝试先卸载libv8 gem,然后安装rubyracer,然后libv8

 gem uninstall libv8 gem install therubyracer gem install libv8 -- --with-system-v8 

Tertom的解决scheme发布在github上解决了我之后,尝试所有其他解决scheme提出的各自的github问题和在这里。
我有完全相同的系统configuration。
这是在el capitan,所以不是一个确切的答案的问题,但人们可能会发现这个信息有帮助。

我在这里引用它的可见性:

解决了同样的问题

  • MacOS 10.11.2
  • ruby1.9.3
  • libv8 3.16.14.13
  • therubyracer 0.12.2

 brew tap homebrew/versions brew install v8-315 brew link --force v8-315 bundle install brew unlink v8-315 

如果你也不能安装libv8,

 gem install libv8 --with-system-v8 

要么

 bundle config build.libv8 --with-system-v8 

以上的答案对我来说并不合适。 我的bundlerconfiguration启用了disable-shared-gems ,这会导致其他问题。

我使用的是优胜美地10.10.1,Rails 3.2.x和Ruby 1.9.3p550。

在我的bin/setup的以下片段已经解决了我的问题。

 if ! bundle show therubyracer; then bundle config build.libv8 --with-system-v8 gem install --install-dir vendor/bundle libv8 -v 3.16.14.7 gem install libv8 -v 3.16.14.7 gem install --install-dir vendor/bundle therubyracer fi 

我find了解决上述问题的方法。

这更多的是libv8和therubyracer之间的兼容性。

 gem install libv8 -v '3.3.10.4' -- --with-system-v8 gem install therubyracer -v '0.10.2' 

这应该工作正常,因为两个版本都与我兼容。 最初我试图为therubyracer安装0.12.0版本,并面临这个问题。 一旦我切换到版本0.10.2,一切工作正常。

我目前的操作系统:小牛

打破了我的头近两天后,这为我工作。

 rvm install 2.2.2 gem install rails bundle install 

我注意到当我们遇到问题时:

 Gem::Ext::BuildError: ERROR: Failed to build gem native extension 

然后你应该安装build-essential

 sudo apt install build-essential 

它适用于mini_race的安装问题。

我只是运行软件包更新,它为我工作。

观察:使用Ruby 2.3.0