Assets.github.com%2fimages%2fgravatars%2fgravatar-140

Mac で ruby-1.9.3-p385 がビルドできない問題を素早く解決する Edit

  • takus
  • yu1ch1@github
  • dot@github
  • billikenvy@github
  • akira-t@github
  • hiroism007@github
  • geek_duck
  • hazy_moon
  • gantawitter
  • yito
  • Favi_ty
  • bomcat@github
  • kazuph
  • ofk
  • STAR_ZERO
  • riaf
  • iyuuya
  • FunyaFunya
  • tyabe
  • htty
Edit

Mountain Lion あたりだと ruby-1.9.3-p385 のビルド時に以下のようなエラーが出る:

BUILD FAILED
(略)
Last 10 log lines:
compiling regenc.c
compiling regerror.c
compiling regexec.c
compiling regparse.c
regparse.c:582:15: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    return t->num_entries;
    ~~~~~~ ~~~^~~~~~~~~~~
1 error generated.
make: *** [regparse.o] Error 1

整数の精度を落とすような暗黙的型変換の警告(-Wshorten-64-to-32)と、警告をエラーにするオプション(-Werror)によってビルドが失敗している。

これを解決するには brew install apple-gcc42 して CC=/usr/local/bin/gcc-4.2 すればいいという情報が色々見つかるが、そんなことをしなくても警告を無視するだけでビルドは通る:

export CFLAGS=-Wno-error=shorten-64-to-32
# プリインストールの readline と OpenSSL は壊れているため、別途 Homebrew などでインストールしたものを使う
export CONFIGURE_OPTS="--with-openssl-dir=/path/to/dir --with-readline-dir=/path/to/dir"

rvm install ruby-1.9.3-p385
# or
rbenv install 1.9.3-p385

apple-gcc42 を使えば出ないはずの警告を無視することについて不安があるかもしれないが、 apple-gcc42 は警告のチェックが甘いだけである。

補足:homebrew で入れた openssl を使って Ruby をコンパイルすると SSL 利用時に証明書エラーが発生する場合の対応

Icon-ok
10 users said this post was useful/correct.

Version Information


Sign up and follow uasi :)

Sign up with GitHub/Twitter

x close