mysql2: Gem native extension build fails after upgrade to MacOS 10.4 Mojave
Hi,
Having trouble installing the mysql2 gem after upgrade to MacOS Mojave. Other gems with native extensions do work (i.e. nokogiri). Any help would be greatly appreciated. Thank you!
Environment:
- mysql@5.7 freshly installed via Homebrew
- mysql2 versions attempted: 0.4.9, 0.4.10, 0.5.2 (same outcome for all)
- XCode 10 - I ensured that latest command line tools were installed
Output from build step
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/ext/mysql2
/Users/chriskozlowski/.rbenv/versions/2.3.7/bin/ruby -r ./siteconf20180926-18671-1g3sg4b.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/local/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_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... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql@5.7/5.7.23/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/mysql2-0.5.2/mkmf.log
current directory: /Users/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
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/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2 for inspection.
Results logged to /Users/chriskozlowski/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/mysql2-0.5.2/gem_make.out
gem_make.out
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 26
- Comments: 21 (2 by maintainers)
Commits related to this issue
- Use only 1 build option of "mysql2 gem native extension", for prevent build error Refs. - https://qiita.com/tktcorporation/items/0ef8c930fc18ce72c301 - https://github.com/brianmario/mysql2/issues/100... — committed to machupicchubeta/dotfiles by machupicchubeta 5 years ago
- Bundler: Add OpenSSL config for mysql2 gem https://github.com/brianmario/mysql2/issues/1005#issuecomment-433219580 — committed to antw/dotfiles by antw 4 years ago
To fix for a manual gem install:
To fix for all bundle installs:
This worked for me: https://stackoverflow.com/a/39628463
This solution (mentioned above) worked for me:
HOWEVER I want to give a tip: This solution says to use --global which I think is correct, however other solutions mention doing
bundle config --local ...
but with different options.You need to be aware that --local settings take precedence over --global, so if you using the --local option with some other settings, then later try to set global it will be ignored, and you will think it didnt’ work.
this solution work for me!
On MacOS Catalina, only this made it work : https://medium.com/@konole/tough-love-between-mysql2-ruby-gem-and-macos-mojave-2cb6d389ab16
For 0.3.20
For 0.4.10
Posting for Googlers. To fix this issue I had to run
brew install openssl
followed byrbenv install 2.5.3
(which was already installed) for the Ruby install to pick up the correct openssl version.sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
from
https://gorails.com/setup/osx/10.14-mojave
I ran into this issue today; I fixed it by installing mysql first with homebrew, then installing the gem. Currently running Mac Catalina 10.15.2
brew install mysql
gem install mysql2
I also confront with openssl issue.
I referenced this post,
brew install mysql2 and mysql gems with optional
This way is work for me.
Fixed it after updating mysql gem verion to 0.4.9 to 0.4.10.
That worked! Thank you @andrewhao!
Hi @Karan-Jhaveri , I hope my reply is not too late. I think above comment will work for your case.
To whom concern, I think the cause of this issue is that
openssl on mac is pointing to LibreSSL instead of OpenSSL
stackoverflow discussion. This is the step I’ve done for verification.@chriskozlowski This issue seems to be MacOS default library and not an issue to this library. If this clarifies, maybe we could close the issue? (Sorry, my mistake, I think there’s something could be done on the code side, I have link to relevant Pull Requests in my PR.)
Which openssl are you building against? Do you have it installed with Homebrew (
brew install openssl
)?Is there any other alternative? I tried gem install mysql2 – --with-opt-dir=“$(brew --prefix openssl)” and it successfully installed mysql2-0.5.2 but while bundle install, getting the same error again.