简体   繁体   中英

ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. on Mac 10.12

I tried every solution similar to the question:

Recently , I moved from ubuntu to Mac and I'm trying to install mysql gem on Sierra and after I had installed Ruby , Rails , Mysql,

also I type brew install mysql and it worked for download mysql but not the gem , so my question is not similar.

I typed this mysql --version

and I got mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper

I tried to install mysql2 gem for rails to build a new app

I typed this sudo gem install mysql2 and got this error:

Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/mohammed.elias/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170102-2045-18gcs95.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.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 errmsg.h... yes
checking for mysqld_error.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.16/lib
-----
creating Makefile

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

  /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/mkmf.log

current directory:     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean

current directory:     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/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/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysq l2-0.4.5 for inspection.
Results logged to     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/gem_make.out

我的问题很好的答案,感谢@Holger只是在githup ld上引用这个问题:在Mac OS Sierra升级后找不到-lssl`的库

Had this exact same problem when installing MySQL2 gem on a fresh Macbook Pro Sierra.

You need to alter your environment variables to include the following (just replace the 0.0.00 with the desired version of MySQL2 gem:

gem install mysql2 -v '0.0.00' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Also, your $PATH should be set up with mysql with bash profile, a list of settings that will be run every time bash starts. Your bash profile can be found in your home directory under the filename .bash_profile . If it is not created, you can create the text file using the command nano .bash_profile (you should be in your home directory (~)). Add this to your bash profile:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

This line will add the above directories to your path, including the mysql path. Make sure you restart your terminal, as .bash_profile only runs when the terminal is initially loaded.

由于某种原因运行xcode-select --install ,为我解决了这个问题。

For anybody still experiencing the issue:

Run xcode-select --install will set up your command line tools

then set these build flags (for the local application) by running the following:

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

and then finally: bundle install to install the mysql2 gem and other gems worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM