環境
・mac0S 10.15(catalina)
・rails6
・ruby2.6.4
・mysql8.0
bundle install時に下記のエラー。mysql2でこける。
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/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2/ext/mysql2
/Users/username/.rbenv/versions/2.6.4/bin/ruby -I /Users/username/.rbenv/versions/2.6.4/lib/ruby/site_ruby/2.6.0 -r
./siteconf20191026-91303-utrix.rb extconf.rb --with-cppflags\=-I/usr/local/opt/openssl/include
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/local/opt/mysql@8.0/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/opt/mysql@8.0/lib
-----
creating Makefile
current directory: /Users/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2 for
inspection.
Results logged to
/Users/username/rails_projects/projectname/vendor/bundler/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out
Catalinaにアップデート後のエラーかと思い、下記の記事参考に試す。
https://qiita.com/koshilife/items/04122a7b14f2483943aa
xcode-select --install
エラーは消えなかった。
調べてみるとopensslあたりが怪しいと思い、opensslの情報をみる。
brew info openssl
下記のエラー。
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.3.7.mavericks.bottle.tar.gz
Already downloaded: /Users/username/Library/Caches/Homebrew/portable-ruby-2.3.7.mavericks.bottle.tar.gz
==> Pouring portable-ruby-2.3.7.mavericks.bottle.tar.gz
Error: Failed to vendor ruby 2.6.3.
Error: Failed to upgrade vendor Ruby.
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.1.5/lib/concurrent/map.rb:3:in `require': cannot load such file -- concurrent/synchronization (LoadError)
from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.1.5/lib/concurrent/map.rb:3:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object/blank.rb:4:in `require'
from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object/blank.rb:4:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `require'
from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
中国語の記事で、同じ事例の解決方法が書いてあったので試す。
https://blog.csdn.net/wx0628/article/details/88123882
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew info openssl
上のコマンドでのエラーは消えた。
bundle installを再度試す。
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/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2/ext/mysql2
/Users/username/.rbenv/versions/2.6.4/bin/ruby -I /Users/username/.rbenv/versions/2.6.4/lib/ruby/site_ruby/2.6.0 -r
./siteconf20191026-43713-10hxitd.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/username/.rbenv/versions/2.6.4/bin/$(RUBY_BASE_NAME)
/Users/username/.rbenv/versions/2.6.4/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/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:552:in `try_link0'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
from /Users/username/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
from /Users/username/.rbenv/versions/2.6.4/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/username/rails_projects/projectname/vendor/bundler/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/username/rails_projects/projectname/vendor/bundler/gems/mysql2-0.5.2 for
inspection.
Results logged to
/Users/username/rails_projects/projectname/vendor/bundler/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.
mkmfのあたりでエラーが起きてる。こちらの記事を参考に下記のコマンドを試す。
https://qiita.com/tktcorporation/items/0ef8c930fc18ce72c301
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
再度、bundle installしエラー解消。
bundle install