0
0

macOS で glib2 gem がインストールできなかった

Posted at

はじめに

Ruby で pango や poppler といった gem を使っているが,最新版(4.2.2)をインストールしようとしたらエラーが出てインストールできなかった。

エラーをよく見ると,これらが依存している glib2 gem のインストールでコケているのだった。

最終的には解決したのでその記録。

環境は以下のとおり。

  • macOS Sonoma 14.3.1
  • ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin20]

なお,poppler などの gem と,それが依存している glib2 gem のバージョンは揃っている(例えば poppler 4.2.2 は glib2 4.2.2 を使う)。

glib2 のインストール失敗

gem install glib2

とやったら以下のように出て,インストールに失敗する。

ERROR:  Error installing glib2:
	ERROR: Failed to build gem native extension.

    current directory: /Users/XXXX/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/glib2-4.2.2/ext/glib2
/Users/XXXX/.rbenv/versions/3.3.0/bin/ruby extconf.rb
checking for --enable-debug-build option... no
checking for -Wall option to compiler... yes
checking for -Wcast-align option to compiler... yes
checking for -Wextra option to compiler... yes
checking for -Wformat=2 option to compiler... yes
checking for -Winit-self option to compiler... yes
checking for -Wlarger-than-65500 option to compiler... yes
checking for -Wmissing-declarations option to compiler... yes
checking for -Wmissing-format-attribute option to compiler... yes
checking for -Wmissing-include-dirs option to compiler... yes
checking for -Wmissing-noreturn option to compiler... yes
checking for -Wmissing-prototypes option to compiler... yes
checking for -Wnested-externs option to compiler... yes
checking for -Wold-style-definition option to compiler... yes
checking for -Wpacked option to compiler... yes
checking for -Wp,-D_FORTIFY_SOURCE=2 option to compiler... yes
checking for -Wpointer-arith option to compiler... yes
checking for -Wundef option to compiler... yes
checking for -Wout-of-line-declaration option to compiler... yes
checking for -Wunsafe-loop-optimizations option to compiler... no
checking for -Wwrite-strings option to compiler... yes
checking for Homebrew... yes
checking for gobject-2.0 version (>= 2.12.0)... no (nonexistent)
installing 'glib' native package... succeeded
checking for gobject-2.0 version (>= 2.12.0)... no (nonexistent)
*** 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=${opt-dir}/include
	--without-opt-include
	--with-opt-lib=${opt-dir}/lib
	--without-opt-lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/XXXX/.rbenv/versions/3.3.0/bin/$(RUBY_BASE_NAME)
	--enable-debug-build
	--disable-debug-build
	--with-pkg-config
	--without-pkg-config
	--with-override-variables
	--without-override-variables

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/XXXX/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/extensions/arm64-darwin-20/3.3.0/glib2-4.2.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/XXXX/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/glib2-4.2.2 for inspection.
Results logged to /Users/XXXX/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/extensions/arm64-darwin-20/3.3.0/glib2-4.2.2/gem_make.out

brew doctor

なにげに

brew doctor

をやってみた。
これは Homebrew で何か問題が生じていないかを調べてくれるもの。

警告がいくつか出たが,その中に「glib」の文字があった。

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  glib

リンクができていない?

なんだかよく分からないが,以下で直るらしい。

brew link glib

やってみたら確かに直った。

解決

Homebrew での glib のリンク問題を解決したら,

gem install glib

で最新版(4.2.2)がふつうにインストールできた。
glib に依存している種々の gem もすべて正常にアップデートできた。

なぜ問題が生じていたのかなど,全然理解できていないが,直ったのでメデタシ。

発端

もともとは,ひとつ前のバージョン(4.2.1)の poppler を使ったアプリが動かないことに気づいたのが発端。

エラーが出て Bundler.require が失敗するのだが,エラーを記録しておかなかったのでここに掲げられない。

そしたら 4.2.2 がリリースされたので(2024-04-02),それをインストールしてみようとしたらインストールできなかった,と。

前節に書いたとおりの解決を見たあと,改めて 4.2.1 で試したら,こちらもエラーは出なくなった。つまり,原因は同じであったようだ。
おそらく,4.2.1 をインストールした時点ではリンクは外れておらず,その後なんらかの原因で外れたのだろう。これにより,既にインストールしてあった gem の読み込みができず,gem のインストールもできない,という状態になったものと思う。

0
0
0

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
0
0