160
139

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OS X El Capitanでlibv8 / therubyracerのbundle installに失敗する問題の解決方法

Last updated at Posted at 2015-11-08

概要

El Capitanをクリーンインストールしてから改めて環境を構築する際に、
therubyracerのGemのインストールで失敗するようになってしまいました。

libv8とtherubyracerのビルド時にオプションを付ける解決方法がWeb上でよく見つかります。
しかし、今回はそれでは解決できず、逆にビルド時のオプションを付けていたことでハマったため
整理することにしました。

TL;DR

[2016.05.04追記]

結局のところ、libv8を最新版にアップデートすれば解決するのですが、新しいXcodeが出たばかりだとlibv8が対応していない場合があります。その場合は、Appleのnon-LLVMな古いGCCをインストールします。

$ brew tap homebrew/dupes
$ brew install apple-gcc42
$ cd /path/to/repos
$ bundle config --local build.libv8 --with-cxx=/usr/local/bin/g++-4.2

libv8を最新にする場合は、ビルドオプションに何も付けません。non-LLVMなGCCを利用する場合は、上記のようにビルドオプションでそのGCCを指定するようにします。それ以外は何も付けません。

発生した問題

エラーメッセージをググってきた人のために、試行錯誤した内容を残しておきます。

libv8がインストールできない

まず、libv8とtherubyracerが依存関係に入っているGemfileでbundle installを実行すると、
以下のエラーが出力されてlibv8がインストールできません。

Installing libv8 3.16.14.7 with native extensions

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

    /Users/user/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151103-82429-igbg9b.rb extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.10
Using compiler: /usr/bin/c++ (clang version 7.0.0)
In file included from ../src/conversions.cc:32:
In file included from ../src/conversions-inl.h:43:
../src/scanner.h:444:5: error: unused typedef '__StaticAssertTypedef__444' [-Werror,-Wunused-local-typedef]
    STATIC_ASSERT(kCharacterLookaheadBufferSize == 1);
    ^
../src/checks.h:283:30: note: expanded from macro 'STATIC_ASSERT'
#define STATIC_ASSERT(test)  STATIC_CHECK(test)
                             ^
../src/checks.h:251:5: note: expanded from macro 'STATIC_CHECK'
    SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__)
    ^
../src/checks.h:240:32: note: expanded from macro 'SEMI_STATIC_JOIN'
#define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b)
                               ^
../src/checks.h:241:39: note: expanded from macro 'SEMI_STATIC_JOIN_HELPER'
#define SEMI_STATIC_JOIN_HELPER(a, b) a##b
                                      ^
<scratch space>:63:1: note: expanded from here
__StaticAssertTypedef__444
^
1 error generated.
make[1]: *** [/path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/conversions.o] Error 1
make: *** [x64.release] Error 2
/path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/ext/libv8/location.rb:35:in `each'
        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/ext/libv8/location.rb:35:in `verify_installation!'
        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/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 -Dwerror=''
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum-dtoa.o
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o
  CXX(target) /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/vendor/v8/out/x64.release/obj.target/preparser_lib/src/conversions.o

extconf failed, exit code 1

Gem files will remain installed in /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7 for inspection.
Results logged to /path/to/repo/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/libv8-3.16.14.7/gem_make.out
An error occurred while installing libv8 (3.16.14.7), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.7'` succeeds before bundling.

libv8にビルドオプションを渡すとtherubyracerがインストールできない

libv8のビルド時に--with-system-v8を渡すように設定してから再びbundle installを実行すると、
今度は以下のエラーが出力されてtherubyracerのインストールが失敗します。

Installing therubyracer 0.12.1 with native extensions

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

    /Users/user/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151103-9900-lv59c9.rb 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
        --without-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/user/.rbenv/versions/2.2.3/bin/$(RUBY_BASE_NAME)
        --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
/path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/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 bundle 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.7 installed. You may
need to special --with-v8-dir options if it is in a non-standard
location

thanks,
The Mgmt

        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/lib/libv8.rb:7:in `configure_makefile'
        from extconf.rb:32:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /path/to/repo/vendor/bundle/gems/therubyracer-0.12.1 for inspection.
Results logged to /path/to/repo/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/therubyracer-0.12.1/gem_make.out
An error occurred while installing therubyracer (0.12.1), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.1'` succeeds before bundling.

therubyracerにビルドオプションを渡してもインストールできない

エラーメッセージにもあるように、今度はtherubyracerのビルド時に--with-v8-dirオプションを渡すように
設定してbundle installを実行すると、メッセージは変わりますがエラーでインストールできません。

Installing therubyracer 0.12.1 with native extensions

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

    /Users/user/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151103-39647-12royrw.rb extconf.rb --with-v8-dir
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
*** 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
        --without-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/user/.rbenv/versions/2.2.3/bin/$(RUBY_BASE_NAME)
        --with-pthreadlib
        --without-pthreadlib
        --with-objclib
        --without-objclib
        --enable-debug
        --disable-debug
        --with-v8-dir
/Users/user/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:1702:in `dir_config': undefined method `split' for true:TrueClass (NoMethodError)
        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/ext/libv8/location.rb:49:in `configure'
        from /path/to/repo/vendor/bundle/gems/libv8-3.16.14.7/lib/libv8.rb:7:in `configure_makefile'
        from extconf.rb:32:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /path/to/repo/vendor/bundle/gems/therubyracer-0.12.1 for inspection.
Results logged to /path/to/repo/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/therubyracer-0.12.1/gem_make.out
An error occurred while installing therubyracer (0.12.1), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.1'` succeeds before bundling.

古いバージョンのv8をインストールしても実行時にエラーになる

Homebrewのversionsを使って古いバージョンのv8をインストールしてみます。

$ brew tap homebrew/versions
$ brew install v8-315
$ brew link --force v8-315

libv8ビルド時のオプションに--with-system-v8を設定するようにします。

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

これでbundle installは通るようになります。
しかし、rakeなどの実行時に以下のエラーが発生します。

dyld: lazy symbol binding failed: Symbol not found: __ZN2v82V821AddGCPrologueCallbackEPFvNS_6GCTypeENS_15GCCallbackFlagsEES1_
  Referenced from: /path/to/repos/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/therubyracer-0.12.1/v8/init.bundle
  Expected in: flat namespace

dyld: Symbol not found: __ZN2v82V821AddGCPrologueCallbackEPFvNS_6GCTypeENS_15GCCallbackFlagsEES1_
  Referenced from: /path/to/repos/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/therubyracer-0.12.1/v8/init.bundle
  Expected in: flat namespace

therubyracerにビルドオプションを渡すとbundle installでエラーになってしまいます。

Installing therubyracer 0.12.1 with native extensions

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

    /Users/user/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151106-82187-1msxt33.rb extconf.rb --with-v8-dir
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
*** 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
        --without-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/user/.rbenv/versions/2.2.3/bin/$(RUBY_BASE_NAME)
        --with-pthreadlib
        --without-pthreadlib
        --with-objclib
        --without-objclib
        --enable-debug
        --disable-debug
        --with-v8-dir
/Users/user/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:1702:in `dir_config': undefined method `split' for true:TrueClass (NoMethodError)
        from /path/to/repos/vendor/bundle/gems/libv8-3.16.14.7/ext/libv8/location.rb:49:in `configure'
        from /path/to/repos/vendor/bundle/gems/libv8-3.16.14.7/lib/libv8.rb:7:in `configure_makefile'
        from extconf.rb:32:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /path/to/repos/vendor/bundle/gems/therubyracer-0.12.1 for inspection.
Results logged to /path/to/repos/vendor/bundle/extensions/x86_64-darwin-15/2.2.0/therubyracer-0.12.1/gem_make.out
An error occurred while installing therubyracer (0.12.1), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.1'` succeeds before bundling.

参考: Fails Install OS X El Capitan - 10.11 Beta (15A215h) · Issue #359 · cowboyd/therubyracer

解決方法

libv8をアップデートする (推奨)

いろいろ試行錯誤しましたが、結局はapple-gcc42を入れる必要も、
ビルドオプションに何か設定する必要もありません。

libv8を最新版にアップデートすれば解決します。

$ bundle update libv8

まだエラーが発生するという場合は、libv8とtherubyracerに対するビルドオプションが
~/.bundle/configに残っていないか確認しましょう。

それでもエラーが発生する場合は、お使いのXcodeのバージョンに対応したlibv8がまだリリースされていないと思われます。
その場合は次のnon-LLVMな古いGCCをインストールする方法を取ります。

XCode 4.2時代のnon-LLVMな古いGCCをインストールする (非推奨)

HomebrewのdupesからAppleのnon-LLVMな古いGCCをインストールします。

$ brew tap homebrew/dupes
$ brew install apple-gcc42

bundle installを実行するときにこのGCCを使うようにします。
環境変数CXXg++コマンドのパスを設定することでも可能ですが、
Gemfileのあるリポジトリにbundle config --localでlibv8のビルドオプションに設定するのがよいでしょう。

$ cd /path/to/repos
$ bundle config --local build.libv8 --with-cxx=/usr/local/bin/g++-4.2

このとき、libv8にもtherubyracerにも他のビルドオプションを渡す必要はありません。

ただ、わざわざDeprecatedなGCCを入れてオプションを設定しなければならないので、この方法は非推奨です。

参考: Snip2Code - Fix libv8 in El Capitan

160
139
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
160
139

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?