DEV Community

sugiarto
sugiarto

Posted on

gem install mysql2 mac m2 error

Got following error during mysql2 gem installation

sugiartos-MacBook-Pro:aaero sugiarto$ gem install mysql2
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/sugiarto/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/mysql2-0.5.6/ext/mysql2
/Users/sugiarto/.rbenv/versions/3.3.3/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/opt/mysql-client/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/opt/mysql-client/lib
-----
creating Makefile

current directory: /Users/sugiarto/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20241114-81402-f1ge80 sitelibdir\=./.gem.20241114-81402-f1ge80 clean

current directory: /Users/sugiarto/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20241114-81402-f1ge80 sitelibdir\=./.gem.20241114-81402-f1ge80
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]
   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 C2x [-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

Gem files will remain installed in /Users/sugiarto/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/mysql2-0.5.6 for inspection.
Results logged to /Users/sugiarto/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/extensions/arm64-darwin-24/3.3.0/mysql2-0.5.6/gem_make.out

A new release of RubyGems is available: 3.5.11 → 3.5.23!
Run `gem update --system 3.5.23` to update your installation.
Enter fullscreen mode Exit fullscreen mode

And fixed using following command:

sugiartos-MacBook-Pro:aaero sugiarto$ gem install mysql2 -- --with-cflags="-Wno-error=implicit-function-declaration" --with-ldflags=-L/opt/homebrew/opt/zstd/lib
Building native extensions with: '--with-cflags=-Wno-error=implicit-function-declaration --with-ldflags=-L/opt/homebrew/opt/zstd/lib'
This could take a while...
Successfully installed mysql2-0.5.6
Parsing documentation for mysql2-0.5.6
Installing ri documentation for mysql2-0.5.6
Done installing documentation for mysql2 after 1 seconds
1 gem installed

Enter fullscreen mode Exit fullscreen mode

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more