Closed5

rmagickのコンパイルが失敗するようになった

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

current directory:
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/rmagick-6.0.1/ext/RMagick
/opt/hostedtoolcache/Ruby/3.3.6/x64/bin/ruby extconf.rb
checking for brew... no
checking for pacman... no
checking for Ruby version >= 3.0.0... 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=${opt-dir}/include
	--without-opt-include
	--with-opt-lib=${opt-dir}/lib
	--without-opt-lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/opt/hostedtoolcache/Ruby/3.3.6/x64/bin/$(RUBY_BASE_NAME)
	--with-pkg-config
	--without-pkg-config
	--with-override-variables
	--without-override-variables
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:504:in
`parse_pc': .pc doesn't exist: <MagickCore> (PackageConfig::NotFoundError)
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:348:in
`declaration'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:289:in
`requires'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:545:in
`block in required_packages'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:374:in
`collect_requires'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:544:in
`required_packages'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:452:in
`collect_libs'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:310:in
`libs'
from
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/pkg-config-1.5.6/lib/pkg-config.rb:591:in
`libs'
	from extconf.rb:330:in `assert_has_dev_libs!'
	from extconf.rb:303:in `assert_can_compile!'
	from extconf.rb:47:in `initialize'
	from extconf.rb:438:in `new'
	from extconf.rb:438:in `<main>'

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

/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/extensions/x86_64-linux/3.3.0/rmagick-6.0.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/gems/rmagick-6.0.1
for inspection.
Results logged to
/home/runner/work/repository/repository/vendor/bundle/ruby/3.3.0/extensions/x86_64-linux/3.3.0/rmagick-6.0.1/gem_make.out

/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in
`run'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:28:in
`build'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in
`build_extension'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in
`block in build_extensions'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in
`each'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/3.3.0/rubygems/installer.rb:844:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/source/rubygems.rb:200:in
`install'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/installer/gem_installer.rb:54:in
`install'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/installer/parallel_installer.rb:156:in
`do_install'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/installer/parallel_installer.rb:147:in
`block in worker_pool'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/worker.rb:62:in
`apply_func'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/worker.rb:57:in
`block in process_queue'
  <internal:kernel>:187:in `loop'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/worker.rb:54:in
`process_queue'
/opt/hostedtoolcache/Ruby/3.3.6/x64/lib/ruby/gems/3.3.0/gems/bundler-2.4.10/lib/bundler/worker.rb:90:in
`block (2 levels) in create_threads'

An error occurred while installing rmagick (6.0.1), and Bundler cannot continue.

In Gemfile:
  rmagick
Error: Process completed with exit code 5.
##[debug]Finishing: bundle install

Matsukura YukiMatsukura Yuki

調査

手元の環境で再現しない

  • NG
    • Github Actions
  • OK
    • macbook pro M1 Pro
    • x86_64 Ubuntu 24 Linux

手探りで試してみる

bundle update rmagick してみたら2024年11月に更新されている依存しているパッケージがあったので上げてみる。

-    pkg-config (1.5.6)
+    pkg-config (1.5.8)

→変化なし。

Matsukura YukiMatsukura Yuki

chatGPT o1-miniにきいてみた。

結果

このエラーは、rmagick gem のネイティブ拡張をビルドする際に必要な ImageMagick のライブラリやヘッダーファイルがシステムに存在しないために発生しています。rmagick は画像処理ライブラリである ImageMagick に依存しており、その開発用パッケージがインストールされていないとビルドに失敗します。

解決方法
以下の手順に従って、必要なパッケージをインストールしてください。

ImageMagick と開発用ヘッダーのインストール

使用している環境が Ubuntu や Debian ベースの場合、以下のコマンドを実行して ImageMagick とその開発用パッケージをインストールします。

bash
Copy code
sudo apt-get update
sudo apt-get install imagemagick libmagickwand-dev
GitHub Actions を使用している場合は、ワークフローの設定ファイル(例: .github/workflows/your_workflow.yml)に以下のステップを追加してください。

yaml
Copy code
- name: Install ImageMagick
  run: sudo apt-get update && sudo apt-get install -y imagemagick libmagickwand-dev
Bundler の再実行

必要なパッケージをインストールした後、再度 bundle install を実行して rmagick gem をインストールします。

bash
Copy code
bundle install
詳細なエラーログの確認

もし問題が解決しない場合、mkmf.log ファイルを確認して具体的なエラー内容を把握してください。ログファイルのパスは以下の通りです。

bash
Copy code
/home/runner/work/minedia-www/minedia-www/vendor/bundle/ruby/3.3.0/extensions/x86_64-linux/3.3.0/rmagick-6.0.1/mkmf.log
ログには不足しているライブラリや具体的なエラー原因が記載されているため、問題解決の手がかりになります。

他の画像処理ライブラリの検討

もし rmagick のインストールが難しい場合、代替として MiniMagick などの他の画像処理ライブラリを検討することも一つの方法です。MiniMagick は ImageMagick をバックエンドに使用しつつ、より軽量で扱いやすいインターフェースを提供します。

ruby
Copy code
# Gemfile
gem 'mini_magick'
bash
Copy code
bundle install
まとめ
rmagick のインストールエラーは主に必要な ImageMagick のライブラリやヘッダーファイルが不足していることが原因です。上記の手順に従って環境を整えることで、問題を解決できるはずです。もしそれでも解決しない場合は、エラーログを詳しく確認し、具体的なエラー内容に基づいて追加の対応を検討してください。



ちょっと筋違いな感じがする。

調査

最新が入っているから、違うと思う。

root@ef564502d051:/app# apt-get install -y imagemagick libmagickwand-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
imagemagick is already the newest version (8:6.9.11.60+dfsg-1.6+deb12u2).
libmagickwand-dev is already the newest version (8:6.9.11.60+dfsg-1.6+deb12u2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Matsukura YukiMatsukura Yuki

存在しないと行っているファイルはありそう。

root@0c4221b09ef2:/app# find / |grep MagickCore.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/MagickCore.pc
Matsukura YukiMatsukura Yuki

よくよく確認したら、docker container内で落ちているのではなく、setup-rubyしているgithub actionsのbundle installで落ちてました。

よって、以下をbundle installより前に追加して解決。

      - name: Install ImageMagick
        run: sudo apt-get update && sudo apt-get install -y imagemagick libmagickwand-dev
このスクラップは2025/01/08にクローズされました