brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.25k stars 550 forks source link

ld: library not found for -limported_openssl on macOS 10.14.6 #1074

Closed gthank closed 1 year ago

gthank commented 5 years ago

mysql2 0.5.2 does not build on Mojave 10.14.6 (18G103), Ruby 2.6.3 via rbenv, mysql@5.6 via Hombrew

Error is during link step: ld: library not found for -limported_openssl

bundle install now fails at Installing mysql2 0.5.2 with native extensions.

I have force reinstalled MySQL and OpenSSL, and bundler is configured w/ home-brew prefix for openssl when building mysql2:

BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt/openssl"

The full build log (mkmf.log):

current directory: /Users/hank/dev/rescuetime-web-beanstalkd-view/vendor/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2
/Users/hank/.rbenv/versions/2.6.3/bin/ruby -I /Users/hank/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20191016-35394-76j9vd.rb extconf.rb --with-opt-dir\=/usr/local/opt/openssl
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/opt/mysql@5.6/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
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/opt/mysql@5.6/lib
-----
creating Makefile

current directory: /Users/hank/dev/rescuetime-web-beanstalkd-view/vendor/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/hank/dev/rescuetime-web-beanstalkd-view/vendor/ruby/2.6.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 -limported_openssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2
toddthomas commented 5 years ago

I had this problem too, with mysql2 0.4.10 and 0.5.2. I learned that linking against -limported_openssl is new in MySQL 5.6.46. See /usr/local/opt/mysql\@5.6/bin/mysql_config. 5.6.46 is new as of Monday, 10/14, and includes changes to allow compiling against OpenSSL 1.1.1. See https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-46.html. So it makes sense that they modified the link statements related to the SSL library.

I don't yet know how to fix this, but I worked around it by reverting my Homebrew mysql@5.6 formula to the last version before the changes to install 5.6.46, and reinstalling, which gets you 5.6.43. This is not a great solution, but here's how I did it:

brew uninstall mysql@5.6
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout f171f1c746db01c283aa137cb24248fbb8eb7a18 Formula/mysql@5.6.rb
brew install mysql@5.6

5.6.43's version of /usr/local/opt/mysql\@5.6/bin/mysql_config is different with respect to SSL lib linking. Instead of -limported_openssl it has -lssl.

JulienSansot commented 5 years ago

git checkout f171f1c746db01c283aa137cb24248fbb8eb7a18 Formula/mysql@5.6.rb didn't work for me. I simply replaced /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mysql@5.6.rb with this version: https://github.com/Homebrew/homebrew-core/blob/f171f1c746db01c283aa137cb24248fbb8eb7a18/Formula/mysql%405.6.rb

gthank commented 5 years ago

@JulienSansot Thanks, this is the route I took. It unblocked me right away.

toddthomas commented 5 years ago

Sorry the git checkout command above didn’t work for you, @JulienSansot. I tried again on my machine and it worked for me. Weird.

johnsyweb commented 5 years ago

Thanks @toddthomas for the pointers.

@JulienSansot: I went around in circles on this one, too. The clue that put me on the right track was here:

% brew install mysql@5.6
Updating Homebrew...
To restore the stashed changes to /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core run:
  'cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash pop'

So I did the git stash pop and checked that I had the correct version of the formula:

% git diff | fgrep 5.6.4
-  url "https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46.tar.gz"
+  url "https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.43.tar.gz"

Then did brew uninstall mysql@5.6 && brew install mysql@5.6 and then I could gem install mysql2.

Phew! Another yak shaved.

mbm-c commented 5 years ago

git checkout f171f1c746db01c283aa137cb24248fbb8eb7a18 Formula/mysql@5.6.rb didn't work for me. I simply replaced /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mysql@5.6.rb with this version: https://github.com/Homebrew/homebrew-core/blob/f171f1c746db01c283aa137cb24248fbb8eb7a18/Formula/mysql%405.6.rb

@JulienSansot Thanks for this.

bhrutledge commented 5 years ago

Instead of the uninstall and checkout, you can reinstall from a URL:

$ brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/f171f1c74/Formula/mysql@5.6.rb

I found the commit hash via:

$ brew log --oneline mysql@5.6
d72887a5a mysql@5.6: brew style --fix
c63dc0143 mysql@5.6: update 5.6.46 bottle.
322f7afae mysql@5.6 5.6.46
f171f1c74 mysql@5.6: update 5.6.43 bottle.
11d8b7fac mysql@5.6: update 5.6.43 bottle.
c0461cdb4 mysql@5.6: no OpenSSL 1.1 support
70961cbfd mysql@5.6: update 5.6.43 bottle.
e579e5ae2 mysql@5.6 5.6.43
8978dc9c6 mysql@5.6: remove references to pre-Mavericks.
0a9a09d9d (grafted) nativefier: update 7.6.9 bottle.
toddthomas commented 5 years ago

Thanks @bhrutledge--that's a very nice feature of brew reinstall I didn't know about.

bhrutledge commented 5 years ago

Also, in case it wasn't clear, I'm guessing this isn't a problem wiith mysql2, but rather with the Homebrew mysql@5.6 formula, or even MySQL itself.

See https://github.com/Homebrew/homebrew-core/issues/45397 for details.

TinNT commented 5 years ago

Thanks @bhrutledge-- you've made my day

ajaya commented 5 years ago

git checkout f171f1c746db01c283aa137cb24248fbb8eb7a18 Formula/mysql@5.6.rb didn't work for me. I simply replaced /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mysql@5.6.rb with this version: https://github.com/Homebrew/homebrew-core/blob/f171f1c746db01c283aa137cb24248fbb8eb7a18/Formula/mysql%405.6.rb

I had this problem too, with mysql2 0.4.10 and 0.5.2. I learned that linking against -limported_openssl is new in MySQL 5.6.46. See /usr/local/opt/mysql@5.6/bin/mysql_config. 5.6.46 is new as of Monday, 10/14, and includes changes to allow compiling against OpenSSL 1.1.1. See https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-46.html. So it makes sense that they modified the link statements related to the SSL library.

I don't yet know how to fix this, but I worked around it by reverting my Homebrew mysql@5.6 formula to the last version before the changes to install 5.6.46, and reinstalling, which gets you 5.6.43. This is not a great solution, but here's how I did it:

brew uninstall mysql@5.6
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout f171f1c746db01c283aa137cb24248fbb8eb7a18 Formula/mysql@5.6.rb
brew install mysql@5.6

5.6.43's version of /usr/local/opt/mysql@5.6/bin/mysql_config is different with respect to SSL lib linking. Instead of -limported_openssl it has -lssl.

You have made my day.

toddthomas commented 5 years ago

This has been fixed in the Homebrew mysql@5.6 formula by https://github.com/Homebrew/homebrew-core/pull/46379.