LoginSignup
1
0

More than 3 years have passed since last update.

mysql2 インストール時エラー ld: library not found for -lssl

Last updated at Posted at 2020-09-30

概要

rubyのプロジェクトの環境設定にて、bundle install 時にmysql2のエラーでこける場合の解消法

  • macOS Catalina 10.15.6
  • ruby version 2.6.3(local、rbenv管理)
  • mysql2(homebrewでインストール済)

エラー

$ bundle install
(・・・略・・・)

current directory: /Users/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/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/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0/mysql2-0.5.3/gem_make.out

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

mysql2でこけてるらしいので、ひとまず言われたとおりに

gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'

すると

(・・・略・・・)

current directory: /Users/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/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/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/{ 名前 }/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0/mysql2-0.5.3/gem_make.out

やっぱりこける。

ld: library not found for -lssl こちらでぐぐると、ライブラリがないという旨のエラー?
下記のサイトが参考になった。

mysql2 インストール時に 「ld: library not found for -limported_openssl」が表示された場合の対応
https://fkmy.hatenablog.com/entry/2019/10/18/022724

解決方法

※(私の環境にはmysql@5.6入ってなかったので)結局のところmysql@5.6を入れれば解決したのかも。
なのだけど、わたしがいったんコケを解消した方法はmysql2の下記のissueにあった方法。

ld: library not found for -lssl after Mac OS Sierra upgrade #795
https://github.com/brianmario/mysql2/issues/795#issuecomment-337006164

こちらのコメント見ると

Step 1.
brew install openssl

Step 2.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

openssl入れて、パス通したらいけたよ報告多数。

実行

opensslは入れてたと思うのだよね。確認。

$ brew list
apr             freetype        jpeg            libpq           openldap        sqlite
apr-util        gdbm            krb5            libssh2         openssl@1.1     tidy-html5
aspell          gettext         libev           libtiff         pcre            unixodbc
autoconf        glib            libevent        libtool         php@7.1         webp
brotli          gmp             libffi          libzip          pkg-config      xz
c-ares          httpd           libiconv        mcrypt          protobuf        zstd
composer        icu4c           libidn          mhash           python@3.8
curl-openssl    jansson         libmetalink     mysql           readline
freetds         jemalloc        libpng          nghttp2         rtmpdump

openssl@1.1 が入ってますね。

※ちなむと今公式でサポートされているのは openssl@1.1 なのでこれは正。

$ brew search openssl
==> Formulae
curl-openssl ✔                                          openssl@1.1 ✔
glib-openssl                                            homebrew/portable-ruby/portable-openssl

というわけで上記issueにあるコマンドたたいてみます。

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

再度、 mysql2のインストール試す。

$ gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Installing ri documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed

いけたっ🙌
再度、バンドルインストール。

$ bundle install 
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/............

(・・・略・・・)

Bundle complete! 24 Gemfile dependencies, 90 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

いけたっ!🙌
めでたしめでたし。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0