【问题标题】:therubyracer - Gem::Ext::BuildError: ERROR: Failed to build gem native extensiontherubyracer - Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展
【发布时间】:2014-06-25 13:22:42
【问题描述】:

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

  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)

显然,rubyracer gem 依赖于 libv8。

1) 安装 libv8

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

我在安装它时遇到了问题,但this great post 既有我的错误,也有关于如何绕过它的解释清楚的答案。

所以我安装了libv8

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

据我了解,这会安装 gem,但使用我本地系统安装的 v8 库,而不是... gem 附带的版本?不管怎样,它是成功的。

2) 安装rubyracer

在下一步中,我在安装 therubyracer gem 时遇到了麻烦。我不太确定这个 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

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

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

谢谢!!

编辑:

  1. 我试过 this solution 卸载 libv8 并通过 brew install 重新安装。在几个类似的问题中也提到了这一点。运气不好。

  2. 我还尝试了CCCXXCPP 环境变量,如here 所述,尽管我认为这没有任何影响,因为它已经在接收我的gcc v4.6编译器。

【问题讨论】:

  • 这个this,也许吧?
  • 总是在 Mac 上安装 therubyracer 时遇到问题 =(

标签: ruby gcc osx-mavericks therubyracer libv8


【解决方案1】:

这些步骤对我有用。

操作系统:特立独行 红宝石:2.1.1

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

【讨论】:

  • 接受这个答案,只做一处改动。我切换了第 3 步和第 2 步以使其正常工作 - 安装 libv8,然后安装 theruby racer。谢谢!
  • 谢谢,这就像一个魅力!我一定是累了,但如果你的说明有尖锐而不是你的版本号会很有帮助,我需要安装不同的版本,但我只是复制你的笔记。
  • 请注意,libv8 版本很关键,正如 here 所述,奇点版本(版本中的最后两位数)也包含二进制文件。
  • 安装/卸载/重新安装舞蹈在 Mojave 上为我工作。我讨厌这种老东西! :D
【解决方案2】:

对于那些在 OS X El Capitan 中遇到这个问题的人,来自 therubyracer 问题线程的this solution 最终对我有用:

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,但我不确定这是否真的有必要。

【讨论】:

  • 我必须在 Gemfile.lock 最终工作之前删除它。谢谢提示。
  • +1,但对于未来的读者,您需要酌情使用gem install libv8 -v 'A.B.C.D'。撰写本文时是 3.16.14.15。
  • +1,如果您想安装特定版本的 therubyracer,请使用:gem install therubyracer -v 'x.x.x' -- --with-v8-dir=/usr/local/opt/v8-315
  • 看起来很像 jottr 的回答。也许让他大喊一声。
  • 对我来说,v8 目录是:/usr/local/opt/v8@3.15
【解决方案3】:

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

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

【讨论】:

  • 不走运 :( 错误中的以下几行似乎很有趣:g++-4.6: error: x86_64: No such file or directory g++-4.6: error: unrecognized option '-arch'
  • 我发现在therubyracer 之前安装libv8 效果更好。
【解决方案4】:

Tertom's 解决方案posted on github 为我解决了这个问题,在尝试了在各自的github issue 和此处提出的所有其他解决方案之后。
我有完全相同的系统配置。
这是关于 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

如果你也无法安装 libv8,

gem install libv8 --with-system-v8

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

【讨论】:

  • 这对我有用。我发现我需要指定 ruby​​racer 期望安装的 libv8 gem 版本。
  • 是的,我相信bundle config build.libv8 --with-system-v8 是我的关键。谢谢!
  • 这是唯一对我有用的东西(并于 2019 年底在 Catalina 上尝试)
  • 非常有帮助,即使 homebrew/versions 已被弃用。我的问题是我当前的链接链接到'/usr/local/bin/d8'。取消链接并运行brew link --force v8-315 对我有用。 2/2020——MacOS 10.15.3。 -- Ruby 版本 1.9.3 -- Bundler 1.16.4 -- libv8 版本 13.16.14.19
【解决方案5】:

对于所有使用 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

【讨论】:

    【解决方案6】:

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

    我正在使用 Yosemite 10.10.1、Rails 3.2.x 和 Ruby 1.9.3p550。

    bin/setup 中的以下 sn-p 已为我解决了该问题。

    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
    

    【讨论】:

      【解决方案7】:

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

      这更像是 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 版本后,一切正常。

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

      【讨论】:

        【解决方案8】:

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

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

        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/v8@3.15
        bundle install
        

        【讨论】:

          【解决方案9】:

          下面的命令在 Catalina 中使用 bundler 为我解决了这个问题

          $ brew install v8@3.15
          $ bundle config build.libv8 --with-system-v8
          $ bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)
          $ bundle install
          

          【讨论】:

            【解决方案10】:

            在折断了我近两天的头之后,这对我有用。

            rvm install 2.2.2
            gem install rails
            bundle install
            

            【讨论】:

              【解决方案11】:

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

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

              试试吧!

              【讨论】:

              • 除非您的项目需要将 LESS 文件编译为 CSS :/
              【解决方案12】:

              就我而言

              MacOS:卡特琳娜, 红宝石:2.3.3使用 rbenv(不是 RVM), 我需要 therubyracer 版本:0.12.3(没关系)

              我尝试了所有解决方案,但什么对我有用,亲爱的,请不要盲目复制粘贴解决方案(bcz 在我的情况下),如果需要,请先阅读并更改以下命令中的版本。大多数命令在大多数现有答案中都很常见,但对我有用的是gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315) 而不是gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315 感谢Junji Zhi 他在this answer 中的评论

              1. brew install gcc
              2. brew tap homebrew/versions   (If it wont work then below 2 steps, for latest MacOS version)
              2.a. brew tap brewsci/bio
              2.b. brew tap brewsci/science
              3. brew install v8-315     (uninstall if v8 installed previously without '-315')
              4. gem install libv8 -v '3.16.14.19' -- --with-system-v8   (Be careful with the libv8 version mentioned in this command, replace version number with one required)
              5.a. gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315    (If it does not work then try below one, In my case below command worked)
              5.b. gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315)
              

              完成,然后继续您的bundle install

              注意:在安装 gem therubyracer 时,检查正在安装的 libv8 版本是否与我在步骤 4 然后,您的 therubyracer 可能无法安装,所以只需做一件事,gem uninstall libv8 然后通过更改版本重复步骤 4 ,您在安装 therubyracer

              时可以在控制台中看到的内容

              【讨论】:

                【解决方案13】:

                这对我有用:

                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

                【讨论】:

                  【解决方案14】:

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

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

                  然后你应该安装 build-essential

                  sudo apt install build-essential
                  

                  它适用于 mini_race 的安装问题。

                  【讨论】:

                    【解决方案15】:

                    我刚刚运行包更新,它对我有用。

                    观察:使用 Ruby 2.3.0

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 1970-01-01
                      • 2015-12-22
                      • 1970-01-01
                      • 1970-01-01
                      • 2014-06-10
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多