プログラミング未経験おじさんの備忘録

本ブログはプログラミング未経験者の拙い学習の記録です。

mysql2のインストール時のエラー対処

しばらく学習進捗の関係でアウトプットをおろそかにしていたのでこちらの更新も順次行い、生活リズムを戻していきたいと思います。

 

早速表題の件ですが、bundle insatall時にmysqlインストール時に止まってしまうエラーが生じてしまったので下記のように単体でインストールした際のエラーを確認してみました。

.....$ gem install mysql2 -v '0.4.10'
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

current directory: /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10/ext/mysql2
/Users/user_name/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20191120-19061-1x902ud.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/opt/mysql@5.6/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
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
-----
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@5.6/lib
-----
creating Makefile

current directory: /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:326:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types]
wrapper->result_buffers[i].is_null = &wrapper->is_null[i];
^ ~~~~~~~~~~~~~~~~~~~~
result.c:328:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types]
wrapper->result_buffers[i].error = &wrapper->error[i];
^ ~~~~~~~~~~~~~~~~~~
2 warnings generated.
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/kuriharatakumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10 for inspection.
Results logged to /Users/kuriharatakumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/mysql2-0.4.10/gem_make.out

ld: library not found for -lsslというような文面があったので調べてみると関連記事で

https://qiita.com/fukudakumi/items/463a39406ce713396403

https://qiita.com/HrsUed/items/ca2e0aee6a2402571cf6

https://qiita.com/paranishian/items/cb0a7bdef8ffa3880327

のようなものがあったのでこちらを参考にしてエラーの改善を行なっていきました。

まず、下記のようなコマンドを実施しました。

.....$ brew info openssl
openssl: stable 1.0.2t (bottled) [keg-only]
SSL/TLS cryptography library
https://openssl.org/
/usr/local/Cellar/openssl/1.0.2s (1,795 files, 12.0MB)
Poured from bottle on 2019-08-16 at 12:35:27
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl.rb
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

==> Analytics
install: 135,887 (30 days), 641,887 (90 days), 5,802,055 (365 days)
install_on_request: 58,872 (30 days), 181,582 (90 days), 879,851 (365 days)
build_error: 0 (30 days)

しかし、こちらのコマンドでは特に記事にあるようなエラー対象となるような文面が表示されなかったので次に-lsslオプションを追加してみます。

.....$ bundle config --local build.mysql2 --with-mysql-config=/usr/local/opt/mysql@5.6/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
You are replacing the current local value of build.mysql2, which is currently nil

こちらのコマンドを実行後に再度インストール実行で問題なく実行することが出来ました。

 

以上、エラー改善報告でした。