brianmario/mysql2

ERROR: occurred while installing mysql2 (0.5.3), and Bundler cannot continue

Rusydy-Mekari opened this issue · 2 comments

Background

I use ruby version 2.6.10 on my M1 Pro Sonoma. Every time I execute bundle install I always stable upon this error:

  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

      current directory: /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
  /Users/username/.rbenv/versions/2.6.10/bin/ruby -I /Users/username/.rbenv/versions/2.6.10/lib/ruby/2.6.0 -r ./siteconf20240617-72248-1ue39ts.rb
  extconf.rb --with-mysql-config\=/opt/homebrew/opt/mysql/bin/mysql_config\ --with-ldflags\=-L/opt/homebrew/opt/zstd/lib\
  -L/opt/homebrew/opt/openssl@3/lib\ --with-cppflags\=-I/opt/homebrew/opt/openssl@3/include\ --with-cflags\=-Wno-error\=implicit-function-declaration
  checking for rb_absint_size()... yes
  checking for rb_absint_singlebit_p()... yes
  checking for rb_wait_for_single_fd()... yes
  -----
  Cannot find mysql_config at /opt/homebrew/opt/mysql/bin/mysql_config --with-ldflags=-L/opt/homebrew/opt/zstd/lib -L/opt/homebrew/opt/openssl@3/lib
  --with-cppflags=-I/opt/homebrew/opt/openssl@3/include --with-cflags=-Wno-error=implicit-function-declaration
  -----
  *** extconf.rb failed ***
  Could not create Makefile due to some reason, probably lack of necessary
  libraries and/or headers.  Check the mkmf.log file for more details.  You may
  need configuration options.

  Provided configuration options:
          --with-opt-dir
          --without-opt-dir
          --with-opt-include
          --without-opt-include=${opt-dir}/include
          --with-opt-lib
          --without-opt-lib=${opt-dir}/lib
          --with-make-prog
          --without-make-prog
          --srcdir=.
          --curdir
          --ruby=/Users/username/.rbenv/versions/2.6.10/bin/$(RUBY_BASE_NAME)
          --with-mysql-dir
          --without-mysql-dir
          --with-mysql-include
          --without-mysql-include=${mysql-dir}/include
          --with-mysql-lib
          --without-mysql-lib=${mysql-dir}/lib
          --with-mysql-config

  To see why this extension failed to compile, please check the mkmf.log which can be found here:

    /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/extensions/arm64-darwin-23/2.6.0/mysql2-0.5.3/mkmf.log

  extconf failed, exit code 1

  Gem files will remain installed in /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
  Results logged to /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/extensions/arm64-darwin-23/2.6.0/mysql2-0.5.3/gem_make.out

  An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
  Make sure that `gem install mysql2 -v '0.5.3'` succeeds before bundling.

  In Gemfile:
    scenic-mysql_adapter was resolved to 1.0.1, which depends on
      mysql2

Then I execute the command gem install mysql2 -v '0.5.3' but get another error:

/Users/username/.rbenv/versions/2.6.10/include/ruby-2.6.0/ruby/ruby.h:1816:5: note: expanded from macro 'RUBY_CONST_ID_CACHE'
    }
    ^
client.c:1621:31: note: ')' token is here
  rb_const_set(cMysql2Client, rb_intern("SSL_MODE_VERIFY_IDENTITY"), INT2NUM(SSL_MODE_VERIFY_IDENTITY));
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/username/.rbenv/versions/2.6.10/include/ruby-2.6.0/ruby/ruby.h:1826:56: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                                                       ^
97 warnings and 1 error generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/username/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/extensions/arm64-darwin-23/2.6.0/mysql2-0.5.3/gem_make.out

That's an odd error message, I don't see why that would be happening. But can you try newer/latest version of the mysql2 gem? Latest is 0.5.6.