LoginSignup
0
0

More than 1 year has passed since last update.

M1 Mac に変えたら mysql2 gem で symbol not found in flat namespace '_mysql_affected_rows' が出た

Last updated at Posted at 2022-06-02

世人もすなるM1 Mac移行といふものを、吾もしてみむとてするなり。

担当しているrubyのプロジェクトで、そろそろM1 Macで開発できるようにしましょうとなり、移行作業しました。
bundle install は問題ありませんでしたが、rspecを実行しようとしたら、次のようなエラーがでました。

LoadError:
  dlopen(/Users/astronoka/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): symbol not found in flat namespace '_mysql_affected_rows' - /Users/astronoka/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle

関数シンボルが見つからず、、、、gem mysql2が正しくビルドできてないみたい。。。

brewでmysql-clientを入れたけど、ちゃんとlibが認識されていないのかも :thinking:

$ brew info mysql-client
mysql-client: stable 8.0.29 (bottled) [keg-only]
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
/opt/homebrew/Cellar/mysql-client/8.0.29 (129 files, 149.0MB)
  Poured from bottle on 2022-06-03 at 01:29:22
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql-client.rb
License: GPL-2.0-only with Universal-FOSS-exception-1.0
==> Dependencies
Build: cmake ✘, pkg-config ✔
Required: libevent ✔, libfido2 ✔, openssl@1.1 ✔, zstd ✔
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /opt/homebrew,
because it conflicts with mysql (which contains client libraries).

If you need to have mysql-client first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> /Users/astronoka/.bash_profile

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"

For pkg-config to find mysql-client you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"

==> Analytics
install: 38,774 (30 days), 85,297 (90 days), 310,430 (365 days)
install-on-request: 33,324 (30 days), 72,951 (90 days), 271,068 (365 days)
build-error: 99 (30 days)

よく見たらLDFLAGSと、CPPFLAGSの指定があったので bundle configで設定してみる。
(brew bundle している間はDiablo Immortalやってました。。)

bundle config build.mysql2 "--with-ldflags=-L/opt/homebrew/opt/mysql-client/lib --with-cppflags=-I/opt/homebrew/opt/mysql-client/include"

この状態で mysql2 を再インストールしたら動きました 🙌

追伸:

brew で インストールした mysql-clientにも mysql_config が存在していました。

$ /opt/homebrew/opt/mysql-client/bin/mysql_config
Usage: /opt/homebrew/opt/mysql-client/bin/mysql_config [OPTIONS]
Compiler: AppleClang 13.1.6.13160021
Options:
        --cflags         [-I/opt/homebrew/opt/mysql-client/include/mysql ]
        --cxxflags       [-I/opt/homebrew/opt/mysql-client/include/mysql ]
        --include        [-I/opt/homebrew/opt/mysql-client/include/mysql]
        --libs           [-L/opt/homebrew/opt/mysql-client/lib -lmysqlclient -lz -L/opt/homebrew/lib -lzstd -L/opt/homebrew/opt/openssl@1.1/lib -lssl -lcrypto -lresolv]
        --libs_r         [-L/opt/homebrew/opt/mysql-client/lib -lmysqlclient -lz -L/opt/homebrew/lib -lzstd -L/opt/homebrew/opt/openssl@1.1/lib -lssl -lcrypto -lresolv]
        --plugindir      [/opt/homebrew/Cellar/mysql-client/8.0.29/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [8.0.29]
        --variable=VAR   VAR is one of:
                pkgincludedir [/opt/homebrew/opt/mysql-client/include/mysql]
                pkglibdir     [/opt/homebrew/opt/mysql-client/lib]
                plugindir     [/opt/homebrew/Cellar/mysql-client/8.0.29/lib/plugin]

指定するオプションは --with-mysql-config だけでよいのかもしれません(未確認)

0
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
0
0