【问题标题】:Installing libv8 gem on OS X 10.9+在 OS X 10.9+ 上安装 libv8 gem
【发布时间】:2013-11-03 20:36:19
【问题描述】:

我正在尝试安装 libv8 3.16.14.3,但在使用最新稳定的 rvm 和 ruby​​-1.9.3-p125 的 OSX Mavericks 上遇到错误。

这是运行命令“gem install libv8”的输出:

~/src(branch:master) » gem install libv8
Fetching: libv8-3.16.14.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
  ERROR: Failed to build gem native extension.

    /Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.5
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Using compiler: g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.
make[1]: *** [/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a] Error 1
make: *** [x64.release] Error 2
/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `each'
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `verify_installation!'
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:26:in `install!'
  from extconf.rb:7:in `<main>'
GYP_GENERATORS=make \
  build/gyp/gyp --generator-output="out" build/all.gyp \
                -Ibuild/standalone.gypi --depth=. \
                -Dv8_target_arch=x64 \
                -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/conversions.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/diy-fp.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fast-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fixed-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/once.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparse-data.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser-api.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/scanner.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/strtod.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/token.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/unicode.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/utils.o
  LIBTOOL-STATIC /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a


Gem files will remain installed in /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3 for inspection.
Results logged to /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/gem_make.out

【问题讨论】:

标签: gem rubygems osx-mavericks osx-yosemite libv8


【解决方案1】:

这是因为 OS X 10.9+ 使用的是 GCC 4.8 版本。如拉取请求 (https://github.com/cowboyd/libv8/pull/95) 中所述,旧版本的 libv8 不正式支持此功能。请尝试在您的 Gemfile 中提高 libv8 的版本(或)bundle update 就足够了。希望这会有所帮助。

来自 libv8 README

自带 V8

因为 libv8 是 ruby​​racer 使用的 V8 引擎的接口,所以您可能需要使用 libv8,即使您已经安装了 V8。如果您希望使用自己的 V8 安装,而不是为您构建,请使用 --with-system-v8 选项。

使用 RubyGems:

gem install libv8 [-v YOUR_VERSION] -- --with-system-v8

使用 Bundler(在您的 Gemfile 中):

捆绑配置 build.libv8 --with-system-v8

请注意,如果您打算运行自己的 V8,则必须同时安装 V8 及其头文件(在 Debian 发行版的 libv8-dev 中找到)。

自带编译器

您可以通过在编译前设置 CXX 环境变量,或者在捆绑配置中添加 --with-cxx= 选项来指定您选择的编译器:

捆绑配置 build.libv8 --with-cxx=clang++

编辑:

如果这个问题是由therubyracer引起的,请按照rider_on_railshere的建议尝试以下操作:

gem 卸载 libv8

gem install therubyracer -v YOUR_RUBY_RACER_VERSION

gem install libv8 -v YOUR_VERSION -- --with-system-v8

【讨论】:

  • 不幸的是,我无法在我正在处理的项目中更改 libv8 的版本。我现在将降级到 OSX 10.8!
  • --with-system-v8 FTW!
  • 谢谢! bundle config build.libv8 --with-system-v8 有帮助!
  • bundle update 让我摆脱了麻木和苹果升级造成的痛苦
  • 如果有人在解决这个问题后遇到therubyracer gem 的以下问题:stackoverflow.com/questions/23536893/…
【解决方案2】:

您实际上可以在 Mavericks 上安装该版本:

gem install libv8 -v 3.11.8.17 -- --with-system-v8

我可以确认这适用于 rbenv 和 ruby​​ 1.9.3p448

【讨论】:

  • 对我来说也一样 - os x 10.9、rbenv 和 ruby​​-2.0.0-p247
  • 在 1.8.7 上为一个旧项目工作 :)
  • 为什么会这样?该命令的哪一部分是--with-system-v8修改的,它在做什么?
  • 按照这里的说明github.com/cowboyd/libv8libv8 允许您使用预先存在的 V8 引擎版本 (en.wikipedia.org/wiki/V8_(JavaScript_engine)) 而不是自己编译。随着 C++ 编译器的变化,编译是小牛队中的一个问题。您可以使用此处的说明自行编译 libV8 (stackoverflow.com/a/19668162/2012130)
  • 适用于 rbenv 和 ruby​​ 2.1.1 - gem install libv8 -- --with-system-v8
【解决方案3】:

我的 El Capitan 解决方案:

$ brew install v8
$ gem install libv8 -v REQUIRED_LIBV8_VERSION -- --with-system-v8

REQUIRED_LIBV8_VERSION 对我来说是 3.16.14.7,但你需要检查你的捆绑包中需要哪个(这是用于 rails 4.2.5 的那个)

您可能还需要以超级用户身份运行上述命令(如果您的 gem 和系统库是全局的)

【讨论】:

  • 您不应该使用 sudo 进行 brew install 或 gem install。这会产生权限问题。
  • @benDangelo,您所说的绝对正确。即使系统有时可能需要 root 权限来安装软件,但在一般情况下使用 sudo 是一种不好的做法。我会编辑我的回复,谢谢。
  • 它对我有用!谢谢。这是唯一可行的解​​决方案。
  • 只安装 v8 为我做了工作......然后无需使用 gem 命令添加标志
【解决方案4】:

您可以配置捆绑程序,而不必了解每个版本。 @3.15 可以替换为其他版本。

$ 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

【讨论】:

  • 适用于 macOS Catalina。谢谢!
  • 你是我的救星,我有相当旧的应用程序依赖于 ruby​​racer。唯一需要注意的是,brew现在没有其他v8版本,只有v8@3.15v8
【解决方案5】:

当我尝试接受的答案时,libv8 会使用gem install libv8 成功安装,但bundle install 在 libv8 上会失败。我认为bundle install 试图安装不同版本的 libv8。我能够找到适合我的解决方案。

我需要 libv8,因为 ruby​​racer 依赖于它。为了安装它,我在 therubyracer 的 gem_make.out 日志中记录了安装失败的版本。 (gem_make.out 日志的路径将在失败消息中。)在我的例子中,它是 3.16.14.7。 (这个版本可能会随着时间的推移而改变,以防你在三年后阅读。)然后我这样做了:

gem install libv8 -v 3.16.14.7 -- --with-v8-lib

这允许它工作:

gem install therubyracer

这让我可以完成我的bundle install

这在 OSX Yosemite 上对我有用。

【讨论】:

  • 我应该注意到,在我升级到 OSX Yosemite 后,bundle install 立即损坏了我,这就是我必须找到这个解决方案的原因。
  • 这在 OS X Yosemite 上运行良好,而许多其他答案根本不起作用。
  • 谢谢伙计。 'therubyracer' 终于安装好了。
【解决方案6】:

我的问题是从therubyracer 开始更新到macOS 10.15ruby-2.6.5

以下对我有用:

brew install v8@3.15

gem install libv8 -v 3.16.14.19 -- --with-system-v8

gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15

【讨论】:

  • 这是唯一能让 therubyracer 在 Catalina 上进行旧项目的方法。谢谢。
  • 谢谢。在 Catalina 为我工作,ruby 2.7.2,rails 5.2.4。
【解决方案7】:

https://github.com/cowboyd/therubyracer/issues/339

在该链接上找到的 jasonlynes 解决方案对我来说是诀窍。其他的都没有用。

brew install homebrew/versions/v8-315
brew link --overwrite v8-315 --force
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-system-v8

【讨论】:

  • 我无法相信为什么这在 2020 年仍然是一个问题......谢谢@Stefanos.Ioannou,这是对我有用的解决方案。
【解决方案8】:

我更新到 ma​​cOS Catalina @ 10.15ruby 2.6.5。过了一会儿又安装了libv8therubyracer,虽然我建议不要更新macOS(我听说ruby 应该没问题)。

首先,我必须更新 XCode

  1. xcode-select --install

我使用rbenv更新ruby,并在/Users/&lt;username&gt;/.rbenv/version中手动设置ruby版本为2.6.5。尽管如果您的项目包含 .ruby-version 文件,这应该无关紧要。

然后我清理了我从libv8(通常在/usr/local/opt/)安装的任何版本:brew uninstall v8brew uninstall libv8@3.15

  1. brew install v8@3.15

现在,跟随https://github.com/cowboyd/libv8#do-i-get-a-binary,我安装了

  1. gem install libv8 -v '3.16.14.19' -- --with-system-v8

然后可以运行bundle install而不会出错。

【讨论】:

    【解决方案9】:

    这些都没有帮助我......无论我做什么,我的 therubyracer gem 安装一直抱怨这个错误:

    Unable to find a compiler officially supported by v8.
    It is recommended to use GCC v4.4 or higher
    Beginning compilation. This will take some time.
    Building v8 with env CXX=clang++ LINK=clang++  /usr/local/bin/gmake x64.release ARFLAGS.target=crs werror=no
    GYP_GENERATORS=make \
    build/gyp/gyp --generator-output="out" build/all.gyp \
                  -Ibuild/standalone.gypi --depth=. \
                  -Dv8_target_arch=x64 \
                  -S.x64 -Dmac_deployment_target=10.15 -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
      File "build/gyp/gyp", line 12
        except ImportError, e:
                          ^
    SyntaxError: invalid syntax
    gmake: *** [Makefile:268: out/Makefile.x64] Error 1
    

    最终帮助我的是我偶然发现的另一个论坛https://www.bountysource.com/issues/82833405-libv8-fails-to-build-on-catalina-10-15

    对我有用的最终解决方案:

    我必须将这些行添加到我的 .zshrc 文件中:

    export CXX=clang++
    export GYPFLAGS=-Dmac_deployment_target=10.15
    

    然后我必须运行这些命令:

    source ~/.zshrc
    brew tap homebrew/homebrew-core
    brew install v8@3.15
    gem uninstall therubyracer
    gem uninstall libv8
    gem install libv8 -v '3.16.14.19' -- --with-system-v8
    gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15
    bundle install
    

    我希望其他人觉得这很有用!

    【讨论】:

      【解决方案10】:

      试试我在这个问题中总结的内容:"gem install therubyracer -v '0.10.2'" on osx mavericks not installing

      它对我有用(OS X Mavericks)

      【讨论】:

        【解决方案11】:

        当我从 OSX Mountain Lion 升级到 OSX Mavericks 时,我遇到了同样的问题。 接受的答案适用于 libv8,但当我去捆绑安装 therubyracer gem 时却不行。

        从 ruby​​-1.8.7-p354 升级到 ruby​​-1.8.7-375 对我有用。 libv8 (3.16.14.3-x86_64-darwin-13) 和 therubyracer (0.12.0) gems 安装没有问题。

        假设你使用 rbenv:

        rbenv versions
          system
          * 1.8.7-p354
          2.0.0-rc2
        
        rbenv uninstall 1.8.7-p354
        rbenv install 1.8.7-p375
        
        rbenv versions
          system
          * 1.8.7-p375
          2.0.0-rc2
        
        bundle install
        

        【讨论】:

          【解决方案12】:

          这对我来说很好用:

          尝试安装这个预编译的 gem:

          https://dl.dropboxusercontent.com/u/7919548/gems/libv8/libv8-3.11.8.17-x86_64-darwin-13.gem (sha1:5ce07aaf4085fff5a5e10fe018fd6b22021bef3b)

          或者,如果您更喜欢自己构建:

            git clone https://github.com/cowboyd/libv8.git
            cd libv8
            git checkout 3.11
            bundle install
            bundle exec rake clean build binary
            gem install pkg/libv8-3.11.8.17-x86_64-darwin-13.gem
          

          来源:https://github.com/cowboyd/libv8/issues/107

          感谢Felix Bünemann 的修复!

          【讨论】:

            【解决方案13】:

            我尝试了先前答案中概述的许多解决方案,但发现运行 bundle(以安装其他缺少的 gem)会尝试重新编译 libv8(尽管已经使用 --with-system-v8 成功安装它)并因此遭受同样的问题。

            最后,我发现删除 libv8 gem,从 ruby​​gems 获取 gem 文件,然后手动安装带有 --with-system-v8 标志的 .gem 文件对我有用。

            gem uninstall libv8
            gem fetch libv8 -v LIBV8_VERSION
            gem install libv8-LIBV_VERSION.gem -- --with-system-v8
            bundle
            

            感谢 Gaurav Agarwal's answer 引导我走上正确的道路!

            【讨论】:

              【解决方案14】:

              您可以尝试通过the libv8 github site.中提到的方法手动编译安装gem

              【讨论】:

                【解决方案15】:

                在带有 RVM 环境和 ruby​​-2.1.1 版本的 MAC-Yosemite 中

                gem install libv8 -v 3.16.14.3 -- --with-v8-lib gem install therubyracer

                在上述命令的帮助下,可以确认这一点。

                【讨论】:

                  【解决方案16】:

                  真正对我有用的是将 ruby​​ 升级到 2.2.0,删除 Gemfile.lock 并重新捆绑。

                  工作就像一个魅力!

                  【讨论】:

                    【解决方案17】:

                    这对我有用。

                    3.16.14.7 替换为您的版本。

                    bundle install
                    gem install libv8 -v '3.16.14.7' -- --with-system-v8
                    
                    bundle install
                    gem uninstall libv8 -v '3.16.14.7' -- --with-system-v8
                    
                    brew install homebrew/dupes/apple-gcc42
                    
                    export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
                    export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
                    export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
                    
                    bundle install
                    

                    【讨论】:

                    • 这会强制使用较旧的 gcc,这充其量只是一个创可贴,并且肯定会在未来引起问题。
                    【解决方案18】:

                    我在 El Cap 上遇到过类似的问题。这就是我所做的。

                    brew tap homebrew/dupes
                    brew install apple-gcc42
                    

                    然后,

                    export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
                    export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
                    export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
                    

                    最后,

                    brew uninstall v8
                    gem install libv8 -v 3.11.8.17 -- --with-system-v8
                    

                    【讨论】:

                      【解决方案19】:

                      我在另一个项目中使用了 Xcode 的测试版,但忘记了。使用xcode-select 切换回来。比如:

                      sudo xcode-select --switch /Applications/Xcode.app/
                      

                      【讨论】:

                        【解决方案20】:

                        从 Gemfile 中删除:

                        gem 'therubyracer', :platforms => :ruby

                        【讨论】:

                        • 这违背了这篇文章的全部目的。
                        猜你喜欢
                        • 1970-01-01
                        • 2013-11-01
                        • 2014-02-12
                        • 2014-12-05
                        • 2014-03-05
                        • 1970-01-01
                        • 1970-01-01
                        • 2014-04-29
                        相关资源
                        最近更新 更多