簡體   English   中英

錯誤:安裝mysql2時出錯:錯誤:無法構建gem原生擴展。 在Mac 10.12上

[英]ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. on Mac 10.12

我嘗試了類似問題的每個解決方案:

最近,我從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獲得了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

我的問題很好的答案,感謝@Holger只是在githup ld上引用這個問題:在Mac OS Sierra升級后找不到-lssl`的庫

在新的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僅在最初加載終端時運行。

由於某種原因運行xcode-select --install ,為我解決了這個問題。

對於仍然遇到問題的人:

運行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 gem和其他寶石為我工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM