Techioz Blog

Gemfile のネイティブ拡張機能を含む unf_ext (0.0.9) のインストール中にエラーが発生しました

概要

次の Gemfile を使用して Ruby プロジェクトのバンドル インストールを実行中に問題が発生しました。

ruby '2.3.1'

source 'http://www.rubygems.org'

gem 'aws-flow', '~> 2.4.0'
gem 'aws-sdk-core', '~> 3.65', '>= 3.65.1'
gem 'aws-sdk', '~> 3.0', '>= 3.0.1'
gem 'nokogiri', '~> 1.10.10'
gem 'activerecord', '~> 5.2', '>= 5.2.3'
gem 'sqlite3', '~> 1.3', '= 1.3.9'
gem 'rubyzip', '~> 1.2', '>= 1.2.3'
gem 'mechanize', '~> 2.7', '>= 2.7.5'
gem 'slack-notifier', '~> 1.5', '>= 1.5.1'
gem 'minitest', '~> 5.8.4'
gem 'connection_pool', '~> 2.2.5'
gem 'httparty', '~> 0.19.1'
gem 'webrick', '~> 1.7.0'
gem 'net-http-persistent', '= 4.0.1'

unf_ext gem のインストール中にエラーが発生し、次のメッセージが表示されます。

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Fetching gem metadata from http://www.rubygems.org/
Fetching version metadata from http://www.rubygems.org/
Fetching dependency metadata from http://www.rubygems.org/
Resolving dependencies..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Using concurrent-ruby 1.2.2
Using minitest 5.8.5
Using thread_safe 0.3.6
Using arel 9.0.0
Using aws-eventstream 1.2.0
Using json 1.8.6
Using mini_portile2 2.4.0
Using lru_redux 0.8.4
Using aws-partitions 1.848.0
Using jmespath 1.6.2
Using aws-sigv2 1.1.0
Using connection_pool 2.2.5
Installing unf_ext 0.0.9 with native extensions

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

    current directory: /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.9/ext/unf_ext
/opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20231113-2866-7e5i1z.rb extconf.rb
checking for main() in -lstdc++... yes
creating Makefile

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

  /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/unf_ext-0.0.9/mkmf.log

current directory: /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.9/ext/unf_ext
make "DESTDIR=" clean

current directory: /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.9/ext/unf_ext
make "DESTDIR="
compiling unf.cc
cc1plus: warning: command line option ‘-Wdeclaration-after-statement’ is valid for C/ObjC but not for C++ [enabled by default]
cc1plus: warning: command line option ‘-Wimplicit-function-declaration’ is valid for C/ObjC but not for C++ [enabled by default]
unf.cc:39:3: sorry, unimplemented: non-trivial designated initializers not supported
   };
   ^
unf.cc:39:3: sorry, unimplemented: non-trivial designated initializers not supported
make: *** [unf.o] Error 1

make failed, exit code 2

Gem files will remain installed in /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.9 for inspection.
Results logged to /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/unf_ext-0.0.9/gem_make.out
Using mime-types-data 3.2023.1003
Using multi_xml 0.6.0
Using net-http-digest_auth 1.4.1
Using ntlm-http 0.1.1
Using webrick 1.7.0
Using webrobots 0.1.2
Using rubyzip 1.3.0
Using slack-notifier 1.5.1
Using sqlite3 1.3.9
Using bundler 1.12.1
Using i18n 1.14.1
Using tzinfo 1.2.11
Using aws-sigv4 1.6.1
Using nokogiri 1.10.10
Using net-http-persistent 4.0.1
An error occurred while installing unf_ext (0.0.9), and Bundler cannot continue.
Make sure that `gem install unf_ext -v '0.0.9'` succeeds before bundling.

提案に従って mkmf.log ファイルを確認しましたが、unf_ext gem がインストールされている理由と、このコンパイル エラーの原因を特定するのに苦労しています。 Gemfile に unf_ext を明示的に含めていませんでしたが、これは別の gem の依存関係のようです。

この問題の解決方法に関するガイダンス、または unf_ext がインストールされる理由に関する洞察をいただければ幸いです。さらに、調整が必要な gem の特定のバージョンがある場合は?

解決策

現時点での修正は、このチケットの修正が利用可能になるまで、古いバージョンを固定する Gemfile にこれを追加するだけです。 https://github.com/knu/ruby-unf_ext/issues/74

gem 'unf_ext', '= 0.0.8'