おいちゃんと呼ばれています

ウェブ技術や日々考えたことなどを綴っていきます

Lion へアップグレードしたら gcc-4.2 と g++-4.2 が見つからなくなったりもしたけれど、私はげんきです

先日の「Lion へアップグレードしたら Homebrew が動かなくなったりもしたけれど、私はげんきです」の続きというか何というか。

Snow Leopard から Lion へアップグレード後、bundle install したらエラーが発生したので現象と対処方法をメモしておきます。

なお、エラーは(別々に)2回発生しましたが、現象も対処方法も類似しているので、ひとつのエントリーにまとめました。

*1. 現象 その1

エラーメッセージを検索キーワードに入れてググる人がおられると思うので、エラーメッセージを長めに引用しました。

$ bundle install --path vendor/bundle Fetching source index for https://rubygems.org/ Installing rake (0.9.2.2) ... Installing json (1.7.3) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/Cellar/ruby/1.9.2-p290/bin/ruby extconf.rb

creating Makefile

make /usr/bin/gcc-4.2 -I. -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1/x86_64-darwin10.8.0 -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1 -I. -I/usr/local/Cellar/readline/6.2.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -w -pipe -march=core2 -msse4 -fno-common -O3 -Wall -o parser.o -c parser.c

make: /usr/bin/gcc-4.2: No such file or directory make: *** [parser.o] Error 1

Gem files will remain installed in /Users/inouetakuya/Dropbox/Projects/y500/src/vendor/bundle/ruby/1.9.1/gems/json-1.7.3 for inspection. Results logged to /Users/inouetakuya/Dropbox/Projects/y500/src/vendor/bundle/ruby/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out An error occured while installing json (1.7.3), and Bundler cannot continue. Make sure that gem install json -v '1.7.3' succeeds before bundling. <<

*2. 現象 その2

$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/......... Using rake (0.9.2.2) ... Installing therubyracer (0.10.1) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/Cellar/ruby/1.9.2-p290/bin/ruby extconf.rb

checking for main() in -lobjc... yes creating Makefile

make /usr/bin/g++-4.2 -I. -I/Users/inouetakuya/Dropbox/Projects/y500/src/vendor/bundle/ruby/1.9.1/gems/libv8-3.3.10.4-x86_64-darwin-10/lib/libv8/v8/include -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1/x86_64-darwin10.8.0 -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/usr/local/Cellar/ruby/1.9.2-p290/include/ruby-1.9.1 -I. -I/usr/local/Cellar/readline/6.2.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -Wall -g -rdynamic -fno-common -O3 -w -pipe -march=core2 -msse4 -fno-common -O3 -w -pipe -march=core2 -msse4 -o rr.o -c rr.cpp

make: /usr/bin/g++-4.2: No such file or directory make: *** [rr.o] Error 1

Gem files will remain installed in /Users/inouetakuya/Dropbox/Projects/y500/src/vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1 for inspection. Results logged to /Users/inouetakuya/Dropbox/Projects/y500/src/vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/ext/v8/gem_make.out An error occured while installing therubyracer (0.10.1), and Bundler cannot continue. Make sure that gem install therubyracer -v '0.10.1' succeeds before bundling. <<

*3. gcc と g++ がインストールされているか確認

Snow Leopard のときは bundler から make できていたので、gcc とか g++ はインストールされているんだろうけど、うまく参照できていないんじゃないかと予想しました。

gcc と g++ がインストールされているか、及びバージョンの確認。

|shell| $ gcc --version i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ||<

うん、やっぱりインストールされていますね。

もし、ここでインストールされていなかったら、下記を参考に「Command Line Tools for Xcode」をインストールしてください。

-Lion へアップグレードしたら Homebrew が動かなくなったりもしたけれど、私はげんきです

*4. gcc 及び g++ へのシンボリックリンクを作成する

前述のとおり、gcc と g++ はインストールされているけど、うまく参照できていないだけだったので、シンボリックリンクを作成しました。

|shell| $ sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2 Password: xxxx

$ sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 ||<

改めて bundle install すると、今度はうまくいきました(解決)

*関連エントリー

-Lion へアップグレードしたら Homebrew が動かなくなったりもしたけれど、私はげんきです