Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem native extension build fails after upgrade to MacOS 10.4 Mojave #1005

Open
chriskozlowski opened this issue Sep 26, 2018 · 22 comments
Open

Comments

@chriskozlowski
Copy link

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:

  • [email protected] 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/[email protected]/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

gem_make.out.txt

@jeremy
Copy link
Contributor

jeremy commented Sep 26, 2018

ld: library not found for -lssl

Which openssl are you building against? Do you have it installed with Homebrew (brew install openssl)?

@chriskozlowski
Copy link
Author

I believe the default Mac OS lib. I actually did install openssl via Homebrew to see if that would work but I do not know how to ensure that the build uses that version. I tried brew link openssl --force but that was a guess. Can you tell me how?

@andrewhao
Copy link

This worked for me: https://stackoverflow.com/a/39628463

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

@chriskozlowski
Copy link
Author

That worked! Thank you @andrewhao!

@feliperaul
Copy link

@andrewhao Thank you!

@jeremy
Copy link
Contributor

jeremy commented Oct 25, 2018

To fix for a manual gem install:

brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"

To fix for all bundle installs:

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install

@jhas3c
Copy link

jhas3c commented Nov 16, 2018

I am still getting this error no solution worked. Please help.
image

Note: This issue is coming just after update to 10.4

@jhas3c
Copy link

jhas3c commented Nov 16, 2018

Fixed it after updating mysql gem verion to 0.4.9 to 0.4.10.

@dukedorje
Copy link

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

@catmando
Copy link

catmando commented Jun 26, 2019

This solution (mentioned above) worked for me:

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install

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.

@joshuapinter
Copy link

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

This worked great. Except, it might actually be better to remove the --local flag here so that it doesn't update the project's .bundle/config file. This way, it's only set on your machine in ~/.bundle/config, since it's likely different from machine to machine.

As per Bundler docs.

@paulohsilvavieira
Copy link

paulohsilvavieira commented Aug 12, 2019

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install

this solution work for me!

@jamesst20
Copy link

jamesst20 commented Nov 12, 2019

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

brew tap frnhr/homebrew-mariadb-connector-c-2
brew install frnhr/mariadb-connector-c-2/mariadb-connector-c
env ARCHFLAGS="-arch x86_64" gem install mysql2 -v '0.3.20' -- --with-mysql-config=/usr/local/Cellar/mariadb-connector-c/2.2.2/bin/mariadb_config  --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

For 0.4.10

brew tap frnhr/homebrew-mariadb-connector-c-2
brew install frnhr/mariadb-connector-c-2/mariadb-connector-c
env ARCHFLAGS="-arch x86_64" gem install mysql2 -v '0.4.10' -- --with-mysql-config=/usr/local/Cellar/mariadb-connector-c/2.2.2/bin/mariadb_config  --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

@davismattg
Copy link

Posting for Googlers. To fix this issue I had to run

brew install openssl followed by rbenv install 2.5.3 (which was already installed) for the Ruby install to pick up the correct openssl version.

@TheCorp
Copy link

TheCorp commented Jan 6, 2020

Saved me just now Matt :)

@ccartano
Copy link

ccartano commented Jan 13, 2020

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

@NickWarm
Copy link

NickWarm commented Feb 7, 2020

I also confront with openssl issue.

ld: library not found for -lssl

I referenced this post,

brew install mysql2 and mysql gems with optional

-- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

This way is work for me.

@tylerdavisgit
Copy link

This worked for me: https://stackoverflow.com/a/39628463

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

I tried this, but still receive an error (now caused by the flags):

From my mkmf.log file:

"clang -o conftest -I/Users/tylerdavis/.rbenv/versions/2.6.6/include/ruby-2.6.0/x86_64-darwin19 -I/Users/tylerdavis/.rbenv/versions/2.6.6/include/ruby-2.6.0/ruby/backward -I/Users/tylerdavis/.rbenv/versions/2.6.6/include/ruby-2.6.0 -I. -I/Users/tylerdavis/.rbenv/versions/2.6.6/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/tylerdavis/.rbenv/versions/2.6.6/lib -L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include -lruby.2.6 " clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include' checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char **argv) 4: { 5: return 0; 6: } /* end */

@Karan-Jhaveri
Copy link

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.

@ngyl88
Copy link

ngyl88 commented Sep 4, 2021

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.

    # To check which openssl you are using
    openssl version
    # Install tool that is used in common stack
    brew install openssl
    # Optional: Add the path to your terminal, if you want to overwrite your default openssl library.
    echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
    # Verify openssl installation is successful
    ls /usr/local/opt/[email protected]/
    # Use this to install local gems
    bundle config --local build.mysql2 --with-cflags="-I/usr/local/opt/[email protected]/include" --with-ldflags="-L/usr/local/opt/[email protected]/lib" && bundle install

@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.)

@puyo
Copy link

puyo commented Mar 8, 2022

If you happen to be using asdf on a Mac (which uses ruby-build), there is a PR that fixes these issues for mysql2 and all other gems that rely on openssl:

rbenv/ruby-build#1440

It'd be great if we got that one merged. Then I could stop patching ruby-build for all my developers using asdf.

@tonyvince
Copy link

tonyvince commented May 23, 2024

I had to use

-- --with-cflags="-Wno-incompatible-function-pointer-types" --with-ldflags=-L/opt/homebrew/opt/openssl@3/lib --with-cppflags=-I/opt/homebrew/opt/openssl@3/include

options to install 0.5.3 version
Mac OS Sonoma 14.4 (23E214)
openssl@1 and openssl@3 installed via homebrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.