在 macOS Sierra 上安装 mysql2 gem



我正在尝试在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

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

修复:

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

libs="$libs -l "

并将其更改为

libs="$libs -l mysqlclient "

解释:

-l-lpthread

链接器不理解选项-l-lpthread-l-l链接器选项相互堵塞。这是因为生成的 make 文件中缺少库名称mysqlclient

尝试使用Home Brew中的mysql-connector-cRuby 2.4.1上为mysql2gem 构建本机扩展时,我遇到了这个问题

这是在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

文件mysql_config中的libs变量应包含:

libs="$libs -l mysqlclient "

而不是

libs="$libs -l "

varembedded_libs也可能是错误的?

mysql-connector-clib 通过Home Brew安装和构建正常,它只是看起来文件mysql_config不正确或生成不正确。

不确定问题的原因。可能是Home Brewmysql-connector-c,mysql2 gem构建过程,用户环境?

问题是您缺少错误消息所示的库

ld:找不到 -l-lpthread 的库

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

ld:找不到 -LSSL 的库

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

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

xcode-select --install

让我知道这是否有帮助!

我不确定问题是 mysql-connector-c 公式在 Homebrew 中被破坏,还是问题出在 mysql2 gem 中,但您可以通过安装 mysql 公式来解决此问题。

即使您不需要本地 MySQL 服务器进行开发,mysql 公式中的mysql_config版本也会正确返回链接 gem 的本机扩展所需的库列表。

如果您已经安装了 mysql-connector-c:

brew unlink mysql-connector-c
# OR
brew uninstall mysql-connector-c

安装 mysql 公式:

brew install mysql

最新更新