在macOS Sierra上安装mysql2 gem

use*_*314 13 ruby mysql ruby-on-rails

我正在尝试在macOS Sierra(10.12.1)上安装mysql2 gem(0.4.5)并收到错误.我没有本地的mysql服务器,它是远程的.

这是错误日志:

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 
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for 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-connector-c/6.1.9/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log   which can be found here:
    /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.4/mkmf.log

current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/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 -l-lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2
Run Code Online (Sandbox Code Playgroud)

有没有人遇到类似的错误?

rob*_*rch 35

固定:

编辑/usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config,找到这一行:

libs="$libs -l "
Run Code Online (Sandbox Code Playgroud)

并将其更改为

libs="$libs -l mysqlclient "
Run Code Online (Sandbox Code Playgroud)

说明:

-l-lpthread

链接器不理解该选项-l-lpthread.两个 -l-l链接器选项相互卡塞.这是因为mysqlclient生成的make文件中缺少库名.

我尝试使用from Home Brewmysql2Ruby 2.4.1上构建gem 的原生扩展时遇到了这个问题mysql-connector-c

这是在MacOS 10.12.5上.

生成的LIBS变量应该看起来像这样:

LIBS = $(LIBRUBYARG_SHARED) -L/usr/local/Cellar/mysql-connector-c/6.1.10/lib -l mysqlclient -lpthread -ldl -lobjc

看来变量是从文件中扩展而来的 /usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config

libs文件中的var mysql_config应包含:

libs="$libs -l mysqlclient "

代替

libs="$libs -l "

var embedded_libs也可能是错的?

mysql-connector-cLIB安装和构建精细通过Home Brew它只是出现的文件mysql_config是不正确或不正确产生.

不确定问题的原因.可能Home Brew,mysql-connector-cmysql2 gem构建过程,用户环境如何?

  • 我也尝试了没有成功的`xcode-select --install`.通过编辑提出的mysql_config`文件,我设法编译了mysql2 gem. (4认同)
  • 很好的分析。这对我有帮助。谢谢 (2认同)

Phi*_*ner 12

问题是您错过了错误消息指示的库

ld:找不到-l-lpthread的库

编辑:似乎有其他相关错误可以通过以下说明修复,即:

ld:找不到-lssl的库

我的猜测是你没有安装xcode,这恰好安装了几个库.请确保通过官方应用商店安装xcode.

可能还需要重新安装命令行工具(即使您已安装xcode并且在某些时候更新了它).

xcode-select --install
Run Code Online (Sandbox Code Playgroud)

如果这有帮助,请告诉我!