camp17-extra / activities

活動記録とわからないことをissueに沢山書きまくるリポジトリ
0 stars 0 forks source link

Ruby2.3.1でmysql2の0.3.18がインストールできなくなった #38

Open popmac opened 7 years ago

popmac commented 7 years ago

起こったこと

Ruby2.3.1でmysql2の0.3.18がインストールできなくなった

環境

$ mysql --version
mysql  Ver 14.14 Distrib 5.6.29, for osx10.11 (x86_64) using  EditLine wrapper

原因

mysqlコマンドを使うためのPATHが通っていなかったため、MySQLのクライアントライブラリの検索に失敗していた

解決方法

.zshrcに以下を追記

export PATH=/usr/local/opt/mysql@5.6/bin:$PATH

参考URL

エラーのログ

※ ユーザー名は適宜usernameに変更

bundle install時のエラー

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

    current directory: /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.3.18/ext/mysql2
/Users/username/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20170727-92153-1wmtmv6.rb extconf.rb
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 mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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.3.1/bin/$(RUBY_BASE_NAME)
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib

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

  /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/mysql2-0.3.18/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/mysql2-0.3.18/gem_make.out

An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.

メッセージの一番最後に書いてあるgem install mysql2 -v '0.3.18'を実行しても同じ内容のエラーが表示された

mkmf.logのログ

$ cat /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/mysql2-0.3.18/mkmf.log
"clang -o conftest -I/Users/username/.rbenv/versions/2.3.1/include/ruby-2.3.0/x86_64-darwin15 -I/Users/username/.rbenv/versions/2.3.1/include/ruby-2.3.0/ruby/backward -I/Users/username/.rbenv/versions/2.3.1/include/ruby-2.3.0 -I. -I/usr/local/include -I/Users/username/.rbenv/versions/2.3.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/username/.rbenv/versions/2.3.1/lib -L/usr/local/lib -L/usr/local/lib/mysql -L. -L/Users/username/.rbenv/versions/2.3.1/lib  -fstack-protector -L/usr/local/lib    -lz -lm  -lruby-static -framework CoreFoundation -lmysqlclient -lz -lm  -lpthread -ldl -lobjc "
ld: warning: directory not found for option '-L/usr/local/lib/mysql'
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10:
11:   return 0;
12: }
13: extern void mysql_query();
14: int t(void) { mysql_query(); return 0; }
/* end */

以下がおそらく原因となっている箇所

ld: warning: directory not found for option '-L/usr/local/lib/mysql'
ld: library not found for -lmysqlclient

試してみたこと

オプションを付けてgem install

/usr/local/libにmysqlのコマンドが入っていないので効果なし

gem install mysql2 -v '0.3.18' -- --with-opt-lib=/usr/local/lib

Rubyの2.3.1をアンインストールして再度インストール

PATHとは関係のないことなので効果なし

そもそもの疑問

疑問-1

疑問-2

疑問-3

popmac commented 7 years ago

知見の共有として載せます!

一番下に疑問も載せてあるので、一応Openにしたままにしておきます。