2013-07-25 116 views
3

我有一個Rails 3.2.13應用程序,我想部署,但託管服務需要MySQL,而不是我一直使用的sqlite。Rails安裝mysql - 安裝mysql2時出錯:錯誤:無法構建gem原生擴展

在從sqlite轉換爲MySQL的過程中,我必須安裝紅寶石寶石mysql2,這是給我安裝時出現以下錯誤:

Error installing mysql2: ERROR: Failed to build gem native extension.

我都試過bundle install,以及gem install mysql2,但出現相同的錯誤消息。

我知道,已經爲許多工作的解決方案是sudo apt-get install libmysql-ruby libmysqlclient-dev,但我對使用Git猛砸視窗,所以我發現一個Windows當量(@弗朗索瓦對this question答案)。我安裝MySQL Server 5.6與安裝程序,並運行以下命令:

gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\include"' 

從我已閱讀,這應該是成功安裝「mysql2」紅寶石寶石。但奇怪的是,我仍然有以下錯誤:

Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-mysql-lib="c:\Program 

Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\i nclude"' This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

 c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb --with-mysql-lib="c:\Pro gram Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\My SQL\MySQL Server 5.6\include" checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes 

checking for rb_intern3()... yes checking for main() in -llibmysql... yes checking for mysql.h... yes checking for errmsg.h... yes checking for mysqld_error.h... yes creating Makefile

make generating mysql2-i386-mingw32.def compiling client.c client.c: In function 'rb_raise_mysql2_error': client.c:139:3: 

warning: ISO C90 forbids mixed declarations and code client.c: In function 'finish_and_mark_inactive': client.c:508:3: warning: ISO C90 forbids mixed declarations and code client.c: In function 'rb_mysql_client_abandon_results': client.c:535:3: warning: ISO C90 forbids mixed declarations and code client.c: In function 'rb_mysql_client_next_result': client.c:938:5: warning: ISO C90 forbids mixed declarations and code compiling mysql2_ext.c compiling result.c result.c: In function 'rb_mysql_result_fetch_fields': result.c:407:35: warning: comparison between signed and unsigned integer express ions linking shared-object mysql2/mysql2.so client.o: In function nogvl_connect': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:158: undefined reference to [email protected]' client.o: In function nogvl_init': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:150: undefined reference to [email protected]' client.o: In function set_ssl_options': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:1078: undefined reference to [email protected]' client.o: In function mysql_client_options': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:723: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:727: undefined reference to [email protected]' client.o: In function rb_mysql_info': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:267: undefined reference to [email protected]' client.o: In function rb_mysql_client_warning_count': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:257: undefined reference to [email protected]' client.o: In function nogvl_do_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:370: undefined reference to [email protected]' client.o: In function rb_mysql_client_more_results': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:923: undefined reference to [email protected]' client.o: In function nogvl_select_db': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:863: undefined reference to [email protected]' client.o: In function nogvl_ping': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:894: undefined reference to [email protected]' client.o: In function rb_mysql_client_thread_id': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:856: undefined reference to [email protected]' client.o: In function rb_mysql_client_last_id': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:825: undefined reference to [email protected]' client.o: In function nogvl_read_query_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:357: undefined reference to [email protected]' client.o: In function rb_mysql_client_server_info': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:788: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:789: undefined reference to [email protected]' client.o: In function rb_mysql_client_info': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:756: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:757: undefined reference to [email protected]' client.o: In function rb_mysql_client_real_escape': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:662: undefined reference to [email protected]' client.o: In function finish_and_mark_inactive': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:515: undefined reference to [email protected]' client.o: In function nogvl_send_query': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:334: undefined reference to [email protected]' client.o: In function nogvl_close': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:190: undefined reference to [email protected]' client.o: In function rb_mysql_client_escape': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:238: undefined reference to [email protected]' client.o: In function rb_raise_mysql2_error': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:125: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:126: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:140: undefined reference to [email protected]' client.o: In function rb_connect': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:297: undefined reference to [email protected]' client.o: In function rb_mysql_client_store_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:966: undefined reference to [email protected]' client.o: In function rb_mysql_client_next_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:939: undefined reference to [email protected]' client.o: In function rb_mysql_client_affected_rows': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:839: undefined reference to [email protected]' client.o: In function rb_mysql_client_async_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:419: undefined reference to [email protected]' client.o: In function rb_mysql_client_abandon_results': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:539: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:538: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:547: undefined reference to [email protected]' client.o: In function nogvl_do_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:368: undefined reference to [email protected]' client.o: In function nogvl_close': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:190: undefined reference to [email protected]' client.o: In function set_charset_name': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:1067: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:1069: undefined reference to [email protected]' client.o: In function init_mysql2_client': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:1105: undefined reference to [email protected]' result.o: In function rb_mysql_result_count': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:576: undefined reference to [email protected]' result.o: In function rb_mysql_result_fetch_field': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:126: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:114: undefined reference to [email protected]' result.o: In function rb_mysql_result_fetch_fields': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:403: undefined reference to [email protected]' result.o: In function nogvl_fetch_row': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:105: undefined reference to [email protected]' result.o: In function rb_mysql_result_free_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:75: undefined reference to [email protected]' result.o: In function rb_mysql_result_fetch_row': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:213: undefined reference to [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:215: undefined reference to [email protected]' result.o: In function rb_mysql_result_each': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:503: undefined reference to [email protected]' result.o: In function rb_mysql_result_free_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:75: undefined reference to [email protected]' result.o: In function rb_mysql_result_each': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:531: undefined reference to [email protected]' result.o: In function rb_mysql_result_free_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:75: undefined reference to [email protected]' result.o: In function rb_mysql_result_each': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:490: undefined reference to [email protected]' result.o: In function rb_mysql_result_free_result': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:75: undefined reference to [email protected]' collect2: ld returned 1 exit status make: *** [mysql2.so] Error 1

Gem files will remain installed in c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/mysql2-0.3.13 

for inspection. Results logged to c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0. 3.13/ext/mysql2/gem_make.out

Can anyone please help? I am having much trouble comprehending what's wrong with the installation. 

回答

15

我對Win64的環境,同樣的錯誤

我測試了很多的解決方案,但。只爲我工作是:

  • 創業板安裝mysql2 -v '0.3.11'
+1

謝謝.. !你救了我.. !! – writeToBhuwan

+0

拯救我們! –

+0

謝謝,我正在嘗試一切! – Will

9

我一直很惱火通過同樣的問題,終於成功安裝mysql2。榮譽[email protected]。看起來我通過Google發現的任何其他解決方案都不適用於我。

here複製並粘貼。所以不要信任我。

gem uninstall mysql2 

Download last MySQL connector from http://cdn.mysql.com/Downloads/Connector-C/mysql- connector-c-noinstall-6.0.2-win32.zip 

Extract it to C:\connector-6.0.2 

gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\connector-6.0.2\lib" --with-mysql-include="C:\connector-6.0.2\include" --with-mysql-dir="C:\connector-6.0.2"' 

關於我的其他信息。

  • 紅寶石1.9.3p392(2013年2月22日)[I386-的mingw32]
  • 滑軌3.2.13
  • MySQL服務器5.6
  • mysql2-0.3.13

PS 即使您成功安裝了mysql2,您仍然需要一些工作(例如mysql2.so(LoadError)),並且在我的情況下,它與libmysql有關,並且似乎是mysql2的另一個主要故障。

+0

,我不得不刪除LIB的包括選項出於某種原因,因爲它是抱怨,它無法找到他們。 .. weird ... 所以對我來說是這樣的:gem install mysql2 --platform = ruby​​ - '--with-mysql-dir =「C:\\ connector-6.0.2」' –

-1

  1. 下載Mysql連接器http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
  2. 提取它。複製的lib \ libmysql.dll的文件,並將其粘貼在Ruby的bin目錄例如:C:\ RailsInstaller \ Ruby1.9.3 \ BIN
  3. 現在重新安裝Mysql2寶石
    創業板安裝mysql2 - 「--with-mysql的-lib =「c:\ Program Files \ MySQL \ MySQL Server 5.0 \ lib \ opt」--with-mysql-include =「c:\ Program Files \ MySQL \ MySQL Server 5。0 \包括「」
    注意:改變mysql安裝路徑按你
  4. 嘗試現在都捆綁
2

我在Windows 7 64位上安裝。什麼工作對我來說是:http://dev.mysql.com/downloads/connector/c/

我把它解壓到C:\溫度

從下載的C 32位連接器存檔。如果您使用不同的目錄,請調整下一個命令。

gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Temp\mysql-connector-c-6.1.3-win32"' 
0

疼痛...很多的痛苦。最後工作做:

(平臺:Windows64bits,Ruby32bits,DevKit32bits ...)

  1. 下載MySQL的連接器C來自http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
  2. 解壓連接器的目錄中沒有空格的名字!
  3. 將lib/libmysql.dll文件複製到ruby/bin中
  4. gem install mysql2 - --with-mysql-dir = D:\ RoR \ mysql-connector-c(如此給出連接器的目錄而不是服務器的目錄)

而且我得到了mysql2 v0.3.17和運行...

相關問題