therubyracer - Gem :: Ext :: BuildError:错误:无法构建gem原生扩展

use*_*003 73 ruby gcc therubyracer libv8 osx-mavericks

我正在尝试在Mavericks上安装以下gem版本

  • libv8(3.16.14.3)
  • therubyracer(0.12.1)

显然,therubyracer宝石取决于libv8.

1)安装libv8

什么是libv8?我的一些研究似乎表明它是Google Chrome使用的某种javascript库?

我在安装它时遇到了麻烦,但是这个很棒的帖子既有我的错误,也有关于如何绕过它的解释清楚的答案.

所以我安装libv8

gem install libv8 -- --with-system-v8
Run Code Online (Sandbox Code Playgroud)

这是我的理解,这安装了gem,但使用我的本地系统安装v8库而不是... gem附带的版本?无论哪种方式,它都是成功的.

2)安装therubyracer

在下一步中,我在安装therubyracergem时遇到了麻烦.我不太确定这个gem是做什么的,只是因为它是我正在尝试的rails项目的依赖项bundle install.

它给了我以下错误:

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
Run Code Online (Sandbox Code Playgroud)

从我可以收集的内容来看,我选择libv8使用我的本地V8库而不是提供的内容进行安装libv8,但现在无法找到本地安装.

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

谢谢!!

编辑:

  1. 我尝试了卸载libv8并重新安装的解决方案brew install.它也提到了几个类似的问题.没运气.

  2. 我也试过了CC,CXXCPP环境变量描述在这里,虽然我不认为有,因为它已经拿起我的任何影响gcc v4.6编译器.

小智 163

这些步骤对我有用.

操作系统:Maverick 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
Run Code Online (Sandbox Code Playgroud)


小智 71

对于那些在OS X El Capitan中遇到此问题的人来说,来自therubyracer问题线程的这个解决方案最终对我有用:

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
Run Code Online (Sandbox Code Playgroud)

我之前也跑过brew install gcc,但我不确定这是否真的有必要.

  • +1,但对于未来的读者,你会想要```gem install libv8 -v'ABCD'```.截至本文撰写时,这是3.16.14.15. (3认同)
  • 对我来说,v8目录是:/usr/local/opt/v8@3.15 (2认同)

小智 26

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

gem uninstall libv8
gem install therubyracer
gem install libv8 -- --with-system-v8
Run Code Online (Sandbox Code Playgroud)


jot*_*ttr 20

在尝试了相应github问题和此处提出的所有其他解决方案后,Tertom 在github上发布解决方案为我解决了这个问题.
我有完全相同的系统配置.
这是el capitan,所以不是问题的确切答案,但人们可能会发现此信息有用.

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

解决了同样的问题

  • MacOS 10.11.2
  • 红宝石1.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
Run Code Online (Sandbox Code Playgroud)

如果你也无法安装libv8,

gem install libv8 --with-system-v8
Run Code Online (Sandbox Code Playgroud)

要么

bundle config build.libv8 --with-system-v8
Run Code Online (Sandbox Code Playgroud)


nza*_*ajt 15

对于所有使用 macOS 10.15 的人来说,brew 已经发生了变化,因此您需要执行这些命令。

brew install v8@3.15
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install
Run Code Online (Sandbox Code Playgroud)


ilo*_*aly 6

上述答案对我不起作用; 我的bundler配置disable-shared-gems启用,这会导致其他问题.

我正在使用Yosemite 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
Run Code Online (Sandbox Code Playgroud)