Reputation: 9808
I have macbook pro m2 machine. I have a ruby project that was working normally and after doing a system upgrade, It's broken.
I'm trying to run bundle install
in my project and I'm getting the below error.
An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue
Fetching gem metadata from https://rubygems.org/.......
Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb --with-opt-dir\=/opt/homebrew/opt/zstd
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
-----
Setting rpath to /opt/homebrew/Cellar/mysql/8.3.0_1/lib
-----
creating Makefile
current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240309-60899-3sw70c sitelibdir\=./.gem.20240309-60899-3sw70c clean
current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240309-60899-3sw70c sitelibdir\=./.gem.20240309-60899-3sw70c
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 C2x [-Wdeprecated-non-prototype]
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 C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
client.c:1438:3: error: call to undeclared function 'mysql_ssl_set'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
mysql_ssl_set(wrapper->client,
^
client.c:1438:3: note: did you mean 'mysql_close'?
/opt/homebrew/Cellar/mysql/8.3.0_1/include/mysql/mysql.h:797:14: note: 'mysql_close' declared here
void STDCALL mysql_close(MYSQL *sock);
^
2 warnings and 1 error generated.
make: *** [client.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-23/3.2.0/mysql2-0.5.5/gem_make.out
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:125:in `run'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:51:in `block in make'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `each'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `make'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:193:in `build_extension'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `each'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `build_extensions'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:852:in `build_extensions'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:76:in `build_extensions'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:28:in `install'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/source/rubygems.rb:205:in `install'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:54:in `install'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:16:in `install_from_spec'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:132:in `do_install'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:123:in `block in worker_pool'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:62:in `apply_func'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:57:in `block in process_queue'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `loop'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `process_queue'
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:90:in `block (2 levels) in create_threads'
An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.
In Gemfile:
mysql2
I could see that it's related to mysql2 package and I followed a lot of tutorials trying to fix it with no solution.
Here are some tips of what I tried before:
$ brew install mysql openssl@3 readline zlib libyaml ncurses libffi gdbm
$ brew install zstd
Set environment variables to help the gem find the necessary libraries: Add the following lines to your shell configuration file (.bash_profile, .zshrc, etc.):
$ export PATH="/opt/homebrew/bin:$PATH"
$ export LDFLAGS="-L$(brew --prefix)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix zstd)/lib"
$ export CPPFLAGS="-I$(brew --prefix)/include -I$(brew --prefix openssl)/include -I$(brew --prefix zstd)/include"
$ export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix zstd)/lib/pkgconfig"
rvm install 3.2.2ruby
Caveats: I have access to 3 Linux Ubuntu machines and 2 mac devices. This is happening only with Mac NOT Ubuntu.
Upvotes: 2
Views: 1645
Reputation: 9808
I solved it by removing the gem lock and applying the following steps:
rm Gemfile.lock
gem install mysql2 -- --with-opt-dir=$(brew --prefix openssl) --with-mysql-dir=$(brew --prefix mysql) --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config
bundle config --local build.mysql2 --with-opt-dir="$(brew --prefix openssl)" --with-mysql-dir="$(brew --prefix mysql)" --with-mysql-config="$(brew --prefix mysql)/bin/mysql_config"
bundle install
Upvotes: 3
Reputation: 17
Please try:
gem install mysql2 -v '0.5.5' -- --with-openssl-dir=$(brew --prefix [email protected]) --with-ldflags=-L$(brew --prefix zstd)/lib
Upvotes: -1