gem install mysql2のエラー対応  LibreSSL編

## 現象

mac でのこのエラー

```
ld: library not found for -lssl
```

こんなふうにインストールの途中で止まる

```
-----
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.25_1/lib
-----
creating Makefile

current directory: [path to]/vendor/bundle/ruby/2.7.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean

current directory: [path to]/vendor/bundle/ruby/2.7.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR="
compiling client.c
client.c:778:14: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka
'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
  rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
             ^~~~~~~~~~~~~
/Users/[USER]/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:25: note: passing argument to parameter here
VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
                        ^
client.c:786:16: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka
'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
    rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0);
               ^~~~~~~~
/Users/[USER]/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:25: note: passing argument to parameter here
VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
                        ^
2 warnings generated.
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 [path to]/vendor/bundle/ruby/2.7.0/gems/mysql2-0.4.10 for inspection.
Results logged to [path to]/vendor/bundle/ruby/2.7.0/extensions/x86_64-darwin-20/2.7.0/mysql2-0.4.10/gem_make.out

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

MacOSのHigh Sierra以降、デフォルトのopensslが、OpenSSLではなくLibreSSLに変更されたのが原因

## openssl インストール

```
$ brew install openssl

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1h: 8,067 files, 18.5MB
```

環境変数に追加

```
$ echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
$ source ~/.zshrc
```

build config 設定

```
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
```

これで先に gem をインストールしてみる

これでもだめなら

```
$ brew upgrade
$ export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"     
$ export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
$ gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
```

### 以前と違う点

with-cppflags も同時にbuild config に設定するとエラーになることがある。
openssl インストール後に出てくるがこれは指定しないほうがいい。

これだけでOK

```
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
```

NG

```
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib --with-cppflags=-I/usr/local/opt/openssl@1.1/include"
```