4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-06-17
$ bundle install

するとmysql2 0.5.2のところでエラー

Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/jun/fout/bb/bu/vendor/bundle/gems/mysql2-0.5.2/ext/mysql2
/Users/jun/.rbenv/versions/2.6.3/bin/ruby -I /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20190617-8478-1oyt6d2.rb extconf.rb
--with-ldflags\=-L/usr/local/opt/openssl/lib\ --with-cppflags\=-I/usr/local/opt/openssl/include
checking for rb_absint_size()... *** 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
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/jun/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
/Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:552:in `try_link0'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
	from /Users/jun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'
	from extconf.rb:25:in `<main>'

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

  /Users/jun/fout/bb/bu/vendor/bundle/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/jun/fout/bb/bu/vendor/bundle/gems/mysql2-0.5.2 for inspection.
Results logged to /Users/jun/fout/bb/bu/vendor/bundle/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

#解決策

rubyのバージョンをプロジェクトに合わせる

$ rbenv local {Rubyバージョン}

Gemfile.lockファイル削除

$ rm  -rf Gemfile.lock
$ brew install openssl
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppf
$ bundle install
4
8
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
4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?