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

有人遇到过类似的错误吗?

最佳答案

修复:
编辑,查找此行:

libs="$libs -l "

把它改成
libs="$libs -l mysqlclient "

说明:
/usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config
链接器不理解选项-l-lpthread。两个链接器选项相互干扰。这是因为生成的make文件中缺少库名称-l-lpthread
我在尝试使用自制的-l-l为Ruby2.4.1上的mysqlclientgem构建本机扩展时遇到了这个问题。
这是10.12.5版的MacOS。
生成的mysql2变量应如下所示:
mysql-connector-c
变量似乎是从文件中展开的
文件中的LIBSvar应包含:
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
varlibs也可能是错误的?
mysql_configlib通过libs="$libs -l mysqlclient "安装并生成fine文件,它只是显示文件libs="$libs -l "不正确或生成不正确。
不确定问题的原因。可能是,mysql2 gem build process,user environment?

关于mysql - 在macOS Sierra上安装mysql2 gem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43661360/

10-12 15:06