错误:安装mysql2时出错:错误:无法构建gem原生扩展。在Mac 10.12上

时间:2017-01-02 10:45:21

标签: mysql ruby-on-rails ruby macos

  

我尝试了类似问题的每个解决方案:

最近,我从ubuntu迁移到Mac,我试图在Sierra上安装mysql gem,之后我安装了Ruby,Rails,Mysql,

我也输入brew install mysql并且它适用于下载mysql而不是gem,所以我的问题不相似。

我输入了mysql --version

我得到了mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper

我尝试安装mysql2 gem for rails来构建新的应用程序

我键入了此sudo gem install mysql2并收到此错误:

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

4 个答案:

答案 0 :(得分:5)

我的问题的一个很好的答案,感谢@Holger只是在githup ld: library not found for -lssl` after Mac OS Sierra upgrade上引用这个问题

答案 1 :(得分:3)

在新Macbook Pro Sierra上安装MySQL2 gem时遇到同样的问题。

您需要更改环境变量以包含以下内容(只需将0.0.00替换为所需版本的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

此外,您的$PATH应该使用带有bash配置文件的mysql进行设置,这是每次bash启动时都会运行的设置列表。您的bash配置文件可以在文件名.bash_profile下的主目录中找到。如果未创建,则可以使用命令nano .bash_profile创建文本文件(您应该在主目录(〜)中)。将其添加到您的bash配置文件中:

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

此行将上述目录添加到您的路径中,包括mysql路径。确保重新启动终端,因为.bash_profile仅在最初加载终端时运行。

答案 2 :(得分:1)

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

答案 3 :(得分:0)

对于仍然遇到此问题的任何人:

运行xcode-select --install将设置您的命令行工具

然后通过运行以下命令设置这些构建标志(对于本地应用程序):

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

,最后: bundle install安装mysql2宝石和其他对我有用的宝石。