⚠️
macOS上でmysql2 gemをビルドしようとすると "ld: library 'zstd' not found" で失敗した件の対処
macOS上でmysql2 gemをビルドしようとしたところ以下のようなエラーで失敗しました。
current directory: /Users/maeda/redmines/gems/ruby/3.3.0/gems/mysql2-0.5.6/ext/mysql2
/Users/maeda/.rbenv/versions/3.3.7/bin/ruby extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
-----
Using --with-openssl-dir=/opt/homebrew/opt/openssl@3
-----
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/9.2.0_3/lib
-----
creating Makefile
current directory: /Users/maeda/redmines/gems/ruby/3.3.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20250403-20822-91ets9 sitelibdir\=./.gem.20250403-20822-91ets9 clean
current directory: /Users/maeda/redmines/gems/ruby/3.3.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20250403-20822-91ets9 sitelibdir\=./.gem.20250403-20822-91ets9
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
43 | mysql2_mysql_enc_name_to_rb_hash (str, len)
| ^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
86 | mysql2_mysql_enc_name_to_rb (str, len)
| ^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:304:35: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
304 | precision = field->length - (field->decimals > 0 ? 2 : 1);
| ~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library 'zstd' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
"ld: library 'zstd' not found" というエラーが確認できますが、zstdはHomebrewでインストール済みでした。
以下のように環境変数 LIBRARY_PATH
を設定してから bundle install
を実行するとインストールできました。
export LIBRARY_PATH="/opt/homebrew/opt/zstd/lib"
Discussion