本日やること
Railsプロジェクトセットアップ
環境
Mac OS Mojave 10.14.3 Ruby 2.6.1
分からないこと
https://qiita.com/egopro/items/aba12261c053eecd6d19#mysql-%E3%82%92%E5%88%A9%E7%94%A8
この記事の最下部にある、『Railsプロジェクトセットアップ』のチャプターまでは進めることができた。 (下が該当部分へのLink)
Bundler で必要な Gem をインストール
rbenv exec bundle install --path vendor/bundle
を実行した際に下のエラーが出てきます。
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Fetching gem metadata from https://rubygems.org/............ Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Fetching rake 12.3.2 Installing rake 12.3.2 Fetching concurrent-ruby 1.1.5 Installing concurrent-ruby 1.1.5 : : (省略) : : Fetching listen 3.1.5 Installing listen 3.1.5 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/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2 /Users/bupolang/.rbenv/versions/2.6.1/bin/ruby -I /Users/bupolang/.rbenv/versions/2.6.1/lib/ruby/2.6.0 -r ./siteconf20190329-52194-vq20pg.rb extconf.rb 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/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/Cellar/mysql/8.0.15/lib ----- creating Makefile current directory: /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2 make "DESTDIR=" clean current directory: /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/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/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2 for inspection. Results logged to /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/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
エラーの中に、
Results logged to /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out
とありましたので、gem_make.out
参照しました。
gem_make.out
current directory: /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2 /Users/bupolang/.rbenv/versions/2.6.1/bin/ruby -I /Users/bupolang/.rbenv/versions/2.6.1/lib/ruby/2.6.0 -r ./siteconf20190329-52194-vq20pg.rb extconf.rb 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/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/Cellar/mysql/8.0.15/lib ----- creating Makefile current directory: /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2 make "DESTDIR=" clean current directory: /Users/bupolang/myproject/cocolog/cocologue/vendor/bundle/ruby/2.6.0/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
mkmf.log
"clang -o conftest -I/Users/bupolang/.rbenv/versions/2.6.1/include/ruby-2.6.0/x86_64-darwin18 -I/Users/bupolang/.rbenv/versions/2.6.1/include/ruby-2.6.0/ruby/backward -I/Users/bupolang/.rbenv/versions/2.6.1/include/ruby-2.6.0 -I. -I/usr/local/Cellar/mysql/8.0.15/include/mysql -I/Users/bupolang/.rbenv/versions/2.6.1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -pipe -DFULL_SSL_MODE_SUPPORT conftest.c -L. -L/Users/bupolang/.rbenv/versions/2.6.1/lib -L. -L/Users/bupolang/.rbenv/versions/2.6.1/lib -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/mysql/8.0.15/lib -lmysqlclient -lssl -lcrypto -lruby.2.6-static -framework Security -framework Foundation -lpthread -ldl -lobjc -Wl,-rpath,/usr/local/Cellar/mysql/8.0.15/lib " ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main() {return 0;} /* end */
試したこと
新しくプロジェクトファイルを作成し、同じ手順を試しましたが、同様のエラーが出てきました。
MySQLがインストールされているか確認し、インストールはされているようです。 (画像は面倒なので省略)
調べたこと
この2つの記事を読みました。 https://skatsuta.github.io/2015/10/03/fail-gem-install/
https://qiita.com/HrsUed/items/ca2e0aee6a2402571cf6
- mysql2のgemをインストール中にエラーが発生している。
ld: library not found for -lssl
から、ssl
というライブラリをリンカーが見つけられない。
のでは?と考えている。
リンカーとは、「コンパイラによって生成されたオブジェクトファイルを受け取り、実行可能なプログラムに結合するプログラム」 (https://www.computerhope.com/jargon/l/linker.htm)