Help us understand the problem. What is going on with this article?

RailsでMysqlを使うときに出たエラーの対処

More than 3 years have passed since last update.

概要

以下のようなエラーログがでてきて、mysql2をinstallするのに失敗してしまった。

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

    current directory: /Users/Kento/work/hituji/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/Kento/.rbenv/versions/2.3.0-dev/bin/ruby -r ./siteconf20161220-15918-1p4ufx4.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/bin/mysql_config
-----
checking for mysql.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
checking for errmsg.h... yes
checking for mysqld_error.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/Cellar/mysql/5.6.19/lib
-----
creating Makefile

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

  /Users/Kento/work/hituji/vendor/bundle/ruby/2.4.0/extensions/x86_64-darwin-15/2.4.0-static/mysql2-0.4.5/mkmf.log

current directory: /Users/Kento/work/hituji/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/Kento/work/hituji/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.5/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/Kento/work/hituji/vendor/bundle/ruby/2.4.0/gems/mysql2-0.4.5 for inspection.
Results logged to /Users/Kento/work/hituji/vendor/bundle/ruby/2.4.0/extensions/x86_64-darwin-15/2.4.0-static/mysql2-0.4.5/gem_make.out
Using puma 3.6.2
Using sass 3.4.23
Using tilt 2.0.5
Using turbolinks-source 5.0.0
Using tzinfo 1.2.2
Using nokogiri 1.6.8.1
Using rack-test 0.6.3
Using sprockets 3.7.1
Using websocket-driver 0.6.4
Using mime-types 3.1
Using coffee-script 2.4.1
Using uglifier 3.0.4
Using rb-inotify 0.9.7
An error occurred while installing mysql2 (0.4.5), and Bundler cannot continue.

問題

libsslが見つからないのが原因。

ld: library not found for -lssl

opensslへのlinkが貼れなくなっているらしいのでlinkを貼るのではなく、pathをしていする。

解決策

pathを見てみて、それをbundle.configに入れる

$ brew reinstall openssl --force
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib


$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした