[英]Install mysql2 gem on macOS Sierra
我正在嘗試在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
。 兩個 -ll
鏈接器選項彼此卡在一起。 這是因為生成的make文件中缺少庫名mysqlclient
。
嘗試使用Home Brew中的mysql-connector-c
在Ruby 2.4.1上為mysql2
gem構建本機擴展時遇到了這個問題
這是在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
var應該包含:
libs="$libs -l mysqlclient "
代替
libs="$libs -l "
var embedded_libs
可能也是錯誤的嗎?
mysql-connector-c
lib可以通過Home Brew
安裝並正常構建,它只是顯示文件mysql_config
不正確或生成不正確。
不知道問題的原因。 可能是Home Brew
, mysql-connector-c
,mysql2 gem的構建過程,用戶環境?
問題是您由於錯誤消息指示而缺少庫
ld:找不到用於-l-lpthread的庫
編輯:似乎還有其他可能與下列指示相關的錯誤,即:
ld:找不到-lssl的庫
我的猜測是您尚未安裝xcode,而恰好會安裝更多的庫。 請確保通過官方應用商店安裝xcode。
也可能需要再次重新安裝命令行工具(即使您已安裝xcode並在某個時候剛剛對其進行了更新)。
xcode-select --install
讓我知道是否有幫助!
我不確定問題是否在於Homebrew中的mysql-connector-c公式已損壞,或者問題是否出在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.