タイトルにもありますが,mysql2をGemfileに記載し、「bundle install」をかけた際、以下のようなエラーが発生しました。ググりまくったのですが解決できなかったため、質問をさせていただきました。以下には現在の状況や考えられる原因を記載しますので、解決策をご存知の方はご指導いただけますと幸いです。
###開発環境
OS MacOsX
rails: 5.1.4
ruby: 2.4.3
発生しているエラー
terminal
1... 2Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 3... 4Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load 5... 6result.c:326:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types] 7 wrapper->result_buffers[i].is_null = &wrapper->is_null[i]; 8 ^ ~~~~~~~~~~~~~~~~~~~~ 9result.c:328:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types] 10 wrapper->result_buffers[i].error = &wrapper->error[i]; 11... 122 warnings generated. 13compiling statement.c 14linking shared-object mysql2/mysql2.bundle 15ld: library not found for -limported_openssl 16clang: error: linker command failed with exit code 1 (use -v to see invocation) 17... 18An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue. 19Make sure that `gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'` succeeds before bundling.
考えられる原因
エラー内容通りに、下のコマンドで確認したところ
terminal
1gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'
結局同じエラーが発生
terminal
1... 22 warnings generated. 3compiling statement.c 4linking shared-object mysql2/mysql2.bundle 5ld: library not found for -limported_openssl 6clang: error: linker command failed with exit code 1 (use -v to see invocation)
次は、**「ld: library not found for -limported_openssl」**の文言から、opensslがあるか確認しました。
terminal
1$ openssl version 2LibreSSL 2.6.5
入ってました。。
さらにググってみると、こういう時はパスを追加するようなので、
terminal
1bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
追記
Opensslのパッケージをインストールしてみました。
terminal
1$ openssl version 2OpenSSL 1.0.2t 10 Sep 2019 3 4$ which openssl 5/usr/local/opt/openssl/bin/openssl 6 7$ brew info openssl 8... 9For compilers to find openssl you may need to set: 10export LDFLAGS="-L/usr/local/opt/openssl/lib" 11export CPPFLAGS="-I/usr/local/opt/openssl/include" 12 13#パスを通す 14$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
追記内容を実行したのですが、エラー内容は未だに変わりません。
もしかすると、パスの通し方が間違っているのでしょうか?
解決策をご存知の方がおられましたら、ご教授いただけますと幸いです。