therubyracer - Gem::Ext::BuildError: 错误:无法构建本地宝石扩展。涉及到 IT 技术。

85

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

  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)

显然,therubyracer gem依赖于libv8。

1)安装libv8

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

我在安装时遇到了麻烦,但这篇很棒的文章解决了我的问题,并详细说明了如何绕过它。

因此我使用以下命令安装了libv8

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

据我理解,这个命令会安装 gem,但是会使用我本地系统安装的 v8 库而非 gem 自带的版本?无论如何,安装成功了。

2) 安装 therubyracer

在接下来的步骤中,我遇到了安装 therubyracer gem 的问题。我不太清楚这个 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
根据我了解的情况,我选择使用本地V8库安装libv8而不是使用提供的libv8。但现在本地安装无法找到。
- 我要如何检查是否已安装V8并如何定位它? - 我尝试了一些指定的标志,但没有一个指向正确的安装目录。 - 这可能是一个单独的话题,但是extconf.rb是什么?我在几个地方看到过。它试图特别使用gcc编译器做什么?
谢谢!
编辑:
1. 我尝试了卸载libv8并通过brew install重新安装的此解决方法。这在几个类似的问题中也被提到。没有成功。
2. 我也尝试了环境变量CCCXXCPP,如此处所述,虽然我认为它没有任何影响,因为它已经选择了我的gcc v4.6编译器。

这个 this,也许可以吗? - dax
2
<sigh>我在Mac上安装therubyracer总是有问题=( - maerics
15个回答

1
我无法在macOS Catalina 10.15上构建therubyracer,因为依赖于libv8,尽管安装了libv8的x64(64位变体)。

对我而言,解决方案是从therubyracer切换到mini_racer,安装mini_racer gem(无需本地构建),然后就可以继续了。

试试吧!


除非您的项目需要将LESS文件编译为CSS:/ - Martin Carel

1

在苦思冥想了将近两天后,这个方法对我有效。

rvm install 2.2.2
gem install rails
bundle install

1
这对我有用:

这对我有用:

gem install libv8 -v '3.16.14.17' -- --with-system-v8
brew install v8-315
gem install therubyracer -v '0.12.3' --source 'http://rubygems.org/' -- --with-v8-dir='/usr/local/opt/v8@3.15'

对于最后一个命令,请检查我的情况下brew --prefix v8-315的输出,它是/usr/local/opt/v8@3.15

-2

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

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

你应该安装 build-essential。

sudo apt install build-essential

对我来说,这解决了mini_race的安装问题。


-3

我刚刚运行了 bundle update,它对我有效。

注意:使用的是 Ruby 2.3.0


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