ruby therubyracer - Gem::Ext::BuildError: 错误:无法构建 gem 本机扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23536893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:28:50  来源:igfitidea点击:

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

rubygccosx-maverickstherubyracerlibv8

提问by user2490003

I'm trying to install the following gem versions on Mavericks

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

  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)
  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)

Obviously therubyracer gems depends on libv8.

显然 therubyracer gems 依赖于 libv8。

1) Installing libv8

1)安装libv8

What is libv8? My bit of research seems to indicaite it's some sort of javascript library used by Google Chrome?

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

I was having trouble installing it, but this great posthad both my error and a well-explained answer on how to bypass it.

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

So I installed libv8with

所以我安装libv8

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

It's my understanding that this installs the gem but uses my local system installation of the v8 library instead of... the version that comes with the gem? Either way, it was successful.

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

2) Installing therubyracer

2)安装rubyracer

During the next step, I had trouble install therubyracergem. I'm not quite sure what this gem does, just that it's a dependency of a rails project I'm trying to bundle install.

在下一步中,我在安装therubyracergem 时遇到了问题。我不太确定这个 gem 有什么作用,只是它是我正在尝试的 Rails 项目的依赖项bundle install

It gives me the following error:

它给了我以下错误:

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

From what I can gather, I chose to install libv8using my local V8 library instead of what was provided with libv8, but now that local installation could not be located.

据我所知,我选择libv8使用本地 V8 库而不是随 提供的库进行安装libv8,但现在无法找到本地安装。

  • How do I check if I do indeed have V8 installed and how do I locate it?
  • I tried a few of the specified flags, none of them seemed to point the gem to the correct installation directory
  • This might be a separate topic, but what is extconf.rb? I've seen it in a few places. And what's it trying to do with the gcccompiler in specific?
  • 如何检查我是否确实安装了 V8 以及如何找到它?
  • 我尝试了一些指定的标志,它们似乎都没有将 gem 指向正确的安装目录
  • 这可能是一个单独的主题,但什么是extconf.rb?我在几个地方见过。它具体想用gcc编译器做什么?

Thanks!!

谢谢!!

EDIT:

编辑:

  1. I tried this solutionof uninstalling libv8 and re-installing via brew install. It was mentioned in a couple of similar questions as well. No luck.

  2. I also tried the CC, CXX, and CPPenvironment variables as described here, although I don't think that has any effect as it was already picking up my gcc v4.6compiler.

  1. 我想这个解决方案通过卸载libv8和重新安装的brew install。在几个类似的问题中也提到了这一点。没运气。

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

回答by rider_on_rails

This steps worked for me.

这些步骤对我有用。

OS: Maverick Ruby: 2.1.1

操作系统: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

回答by Andy Stuhl

For those facing this problem in OS X El Capitan, this solutionfrom a therubyracer issue thread was what finally worked for me:

对于那些在 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

I had also run brew install gccprior, but I'm not sure whether this was in fact necessary.

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

回答by Nikhil

Try first uninstalling libv8 gem, then install rubyracer, and then libv8

尝试先卸载 libv8 gem,然后安装 ruby​​racer,然后安装 libv8

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

回答by jottr

Tertom'ssolution posted on githubsolved it for me, after having tried all other solutions proposed on the respective github issueand here.
I had the exact same system configuration.
This is on el capitan, so not an exact answer to the question, but people might find this info helpful.

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

I'm citing it here for visibility:

我在这里引用它以提高知名度:

Solved the same problem

  • MacOS 10.11.2
  • ruby 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

If you also cannot install libv8,

gem install libv8 --with-system-v8

or

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

解决了同样的问题

  • macOS 10.11.2
  • 红宝石 1.9.3
  • libv8 3.16.14.13
  • 红宝石赛车 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

回答by nzajt

For all of you out there using macOS 10.15, brew has has changed so you will need to do these commands.

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

brew install [email protected]
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/[email protected]
bundle install

回答by iloveitaly

The above answers did not work for me; my bundler confighas disable-shared-gemsenabled which causes additional issues.

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

I'm using Yosemite 10.10.1, Rails 3.2.x, and Ruby 1.9.3p550.

我使用的是 Yosemite 10.10.1、Rails 3.2.x 和 Ruby 1.9.3p550。

The following snippet in my bin/setuphas fixed the issue for me.

我的以下代码段为我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

回答by arpiagar

I found a workaround to the above problem.

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

This is more of a compatibility among libv8 and therubyracer.

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

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

gem install therubyracer -v '0.10.2'

This should work fine as both the versions are compatible with me. Initially I was trying to install the version 0.12.0 for therubyracer and was facing the issue. Once I switched to version 0.10.2, everything worked fine.

这应该可以正常工作,因为这两个版本都与我兼容。最初,我试图为 therubyracer 安装 0.12.0 版本,但遇到了这个问题。切换到 0.10.2 版后,一切正常。

My current OS: Mavericks

我目前的操作系统:小牛队

回答by Mavka Poltavka

I've got this issue for MacOS Mojave 10.14.2and I was able to fix this issue when I found where package v8-315was installed and what the folder name was. In my case, it was here /usr/local/opt/[email protected].

我遇到了这个问题,MacOS Mojave 10.14.2当我找到v8-315安装包的位置和文件夹名称时,我能够解决这个问题。就我而言,它在这里/usr/local/opt/[email protected]

To fix this, I've run next:

为了解决这个问题,我运行了下一个:

brew install v8-315
gem install libv8 -v '3.16.14.15' -- --with-system-v
gem install therubyracer -v '0.12.2' -- --with-system-v8 --with-v8-dir=/usr/local/opt/[email protected]
bundle install

回答by Snips

I couldn't get therubyracer to build on macOS Catalina 10.15 due to the libv8 dependency, despite installing the x64 (64-bit variant) of libv8.

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

The solution for me, was to switch from therubyracer to mini_racer, the mini_racer gem installed (without needing to build locally) and, hey presto! I could continue.

对我来说,解决方案是从 therubyracer 切换到 mini_racer,安装了 mini_racer gem(无需在本地构建),嘿,快!我可以继续。

Try it!

尝试一下!

回答by Sunil Sharma

After breaking my head for almost two days this worked for me.

在打破我的头将近两天后,这对我有用。

rvm install 2.2.2
gem install rails
bundle install