3

I am trying to install the mysql2 gem.

I am using Ruby version 2.7.6 installed using rbenv with the following environment variables set:

export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
export LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/opt/openssl@1.1/lib/"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.1"
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:"/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

I have openssl 1.1 installed

running the following command:

gem install mysql2 -v '0.5.4' -- --with-opt-dir=$(brew --prefix openssl@1.1) --with-ldflags=-L$(brew --prefix zstd)/lib

brings on this error that seems to indicate zlib cannot be found:

ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... no
# -----
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
# -----
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/8.0.33/lib
# -----
creating Makefile

current directory: /Users/hopebradley/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/mysql2-0.5.4/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/hopebradley/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/mysql2-0.5.4/ext/mysql2
make "DESTDIR="
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
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 -lzlib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Tried running:

gem install mysql2 -v '0.5.4' -- --with-opt-dir=$(brew --prefix openssl@1.1) --with-ldflags=-L$(brew --prefix zstd)/lib

After installing all known dependencies using homebrew. Also tried:

bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl@1.1)
bundle install

I have run brew install zstd, gcc and zlib so I should have all the dependencies I need yet I cannot get past this error. I have tried many other things as well but cannot find much information on this error.

Any help would really be appreciated!

tadman
  • 208,517
  • 23
  • 234
  • 262

0 Answers0