我试图安装libv8 3.16.14.3,但在OSX Mavericks上使用最新的稳定rvm和ruby-1.9.3-p125上出现错误。

这是运行命令'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

这是因为OS X 10.9+使用的是GCC的4.8版本。正如pull request (https://github.com/cowboyd/libv8/pull/95)中提到的,旧版本的libv8官方不支持这一点。请尝试在您的Gemfile中升级libv8版本(或)一个bundle更新就足够了。

来自libv8 README

自带V8引擎

因为libv8是therubyracer使用的V8引擎的接口,你可能需要使用libv8,即使你已经安装了V8。如果您希望使用自己的V8安装,而不是让别人为您构建,请使用——with-system-v8选项。

使用RubyGems:

安装libv8 [-v YOUR_VERSION] -- --with-system-v8

使用Bundler(在你的Gemfile中):

包配置构建。libv8——with-system-v8

请注意,如果你打算运行自己的V8,你必须同时安装V8和它的头文件(在libv8-dev for Debian发行版中可以找到)。

自带编译器

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

包配置构建。libv8——with-cxx =叮当声+ +

编辑:

如果这个问题是由therubyracer引起的,请尝试下面由rider_on_rails建议的方法:

Gem卸载libv8 install therubyracer -v YOUR_RUBY_RACER_VERSION 安装libv8 -v YOUR_VERSION -- --with-system-v8


您可以尝试通过libv8 github站点上提到的方法手动编译和安装gem。


你可以在Mavericks上安装这个版本:

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

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


尝试我在这个问题中总结的内容:“gem install therubyracer -v '0.10.2'”在osx mavericks上未安装

对我来说很管用(OS X Mavericks)


这对我来说很有效:

尝试安装这个预编译的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的修复!


当我从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

从Gemfile删除:

Gem 'therubyracer',:platforms =>:ruby


当我尝试接受的答案,libv8将成功安装与gem安装libv8,但捆绑安装将失败在libv8。我认为那个包安装试图安装一个不同版本的libv8。我找到了一个适合我的解决方案。

我需要libv8,因为therubyracer依赖于它。为了安装它,我在gem_make中注意到安装失败的版本。therubyracer的日志。gem_make. xml文件的路径。退出日志将出现在失败消息中。)对我来说是3.16.14.7。(这个版本可能会随着时间的推移而改变,以防你三年后再读这篇文章。)然后我这样做了:

Gem安装libv8 -v 3.16.14.7 -- --with-v8-lib <——注意不同的标志从接受的答案

这使得这个方法可行:

Gem安装therubyracer

这让我完成了我的包安装。

在OSX优胜美地,这招很管用。


在MAC-Yosemite中使用RVM环境和ruby-2.1.1版本

Gem安装libv8 -v 3.16.14.3 -- --with-v8-lib Gem安装therubyracer

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


对我来说真正有用的是将ruby升级到2.2.0,删除Gemfile。再次锁定和捆绑。

效果好极了!


这对我来说很管用。

将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

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

我在酋长岩也遇到过类似的问题,我是这样做的。

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

El Capitan解决方案:

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

Where REQUIRED_LIBV8_VERSION对我来说是3.16.14.7,但你需要检查哪一个是你在你的包中需要的(这是一个rails 4.2.5)

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


我尝试了之前的答案中列出的一些解决方案,但发现运行bundle(安装其他,丢失的gems)会试图重新编译libv8(尽管已经使用——with-system-v8成功安装了它),因此遇到了同样的问题。

最终,我发现删除libv8 gem,从rubygems中获取gem文件,然后手动安装带有——with-system-v8标志的.gem文件对我来说很有效。

i.e.

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

多亏了 高拉夫·阿加瓦尔给我的答案是你指引我走上了正确的道路!


我在另一个项目中使用测试版的Xcode,忘记了。用xcode-select切换回去。喜欢的东西:

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

我更新到macOS Catalina @ 10.15和ruby 2.6.5。过了一段时间,我重新安装了libv8和therubyracer,尽管我建议不要更新macOS(我听说ruby应该没问题)。

首先,我必须更新XCode

xcode-select——安装

我使用rbenv来更新ruby,并在/Users/<username>/中手动设置ruby版本。Rbenv /版本到2.6.5。不过,如果您的项目包含.ruby版本的文件,这应该无关紧要。

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

Brew install v8@3.15

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

安装libv8 -v '3.16.14.19' -- --with-system-v8

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


您可以配置捆绑器,而不必知道每个版本。@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

我的问题是自therubyracer,当更新到macOS 10.15和ruby-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一直抱怨这个错误:

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

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