簡體   English   中英

無法安裝 mysql2 gem

[英]Cannot install mysql2 gem

我無法在我的 Windows7 x64 系統中安裝 mysql2 gem。 我嘗試同時使用 32 位和 64 位版本的 MySQL 服務器,但沒有一個能讓我更進一步。

我安裝了 Ruby 1.8、開發套件和 Rails 平台。 我什至安裝了 minGW 來允許 C++/C 編譯東西。 MySQL 服務器安裝在默認位置。

運行命令時:

C:\Users\Arne>gem install mysql2 -- --with-mysql-include="C:\Program Files (x86)\MySQL\MySQL Server 5.1\include" --with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\"

我從控制台收到以下 output :

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include=${mysql-dir}/include
        --with-mysql-lib=${mysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x
86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL
\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no


Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2 f
or inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2/ext/mysql2/gem_mak
e.out

根據 Rubygems 我的環境的 output 是:

C:\Users\Arne>gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.7.2
  - RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - C:/Ruby/lib/ruby/gems/1.8
     - C:/Users/Arne/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

系統上還安裝了以下 gem:

C:\Users\Arne>gem list --local

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.7)
actionpack (3.0.7)
activemodel (3.0.7)
activerecord (3.0.7)
activeresource (3.0.7)
activesupport (3.0.7)
arel (2.0.9)
builder (3.0.0, 2.1.2)
bundler (1.0.12)
erubis (2.7.0, 2.6.6)
fastthread (1.0.7)
i18n (0.5.0)
mail (2.3.0, 2.2.18)
mime-types (1.16)
mysql (2.8.1 x86-mingw32)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.7.2, 0.6.14)
rack-test (0.5.7)
rails (3.0.7)
railties (3.0.7)
rake (0.8.7)
rdoc (3.5.3, 2.5.11)
rdoc-data (2.5.3)
rubygems-update (1.7.2)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27, 0.3.26)

我不知道有什么遺漏或錯誤,但腳本指向的 output 文件包含以下數據:

mkmf.log:

have_func: checking for rb_thread_blocking_region()... -------------------- no

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I.    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -L.      -lmsvcrt-ruby18-static  -lshell32 -lws2_32  "
conftest.c: In function 't':
conftest.c:7:53: error: 'rb_thread_blocking_region' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4: 
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_blocking_region; return 0; }
/* end */

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I.    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -L.      -lmsvcrt-ruby18-static  -lshell32 -lws2_32  "
C:\Users\Arne\AppData\Local\Temp\ccCicaNu.o: In function `t':
C:\Ruby\lib\ruby\gems\1.8\gems\mysql2-0.3.2\ext\mysql2/conftest.c:3: undefined reference to `rb_thread_blocking_region'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_thread_blocking_region(); return 0; }
/* end */

--------------------

have_library: checking for main() in -llibmysql... -------------------- no

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -LC:\Program -L.      -lmsvcrt-ruby18-static -llibmysql  -lshell32 -lws2_32  "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4: 
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -LC:\Program -L.      -lmsvcrt-ruby18-static -llibmysql  -lshell32 -lws2_32  "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { main(); return 0; }
/* end */

--------------------

gem_make.out:

C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no

我希望有人能指出我做錯了什么,或者我的開發系統中實際上缺少什么來正確安裝和工作這個 gem。

我終於解決了:

  1. 下載安裝MySQL 64bit版本5.5
  2. 下載了 32 位 5.5 版的 zip 存檔。
  3. 將 32 位 include 和 lib 文件夾提取到C:\MySQL
  4. 安裝 Ruby 1.9.2。
  5. 安裝了 Ruby 開發套件。
  6. 安裝寶石:
    1. gem install mysql
    2. gem install mysql2 -- --with-mysql-lib=C:\MySQL\lib --with-mysql-include=C:\MySQL\include
    3. gem install rails
    4. gem install fastthread
    5. gem install haml

它現在就像一個魅力。 似乎 MySQL gem 在處理 64 位時查找數據存在問題。

這對我有用:Win7 64/MySQL 5.5 64-bit/Ruby 1.9.2:

  1. 下載libmysql.dll
  2. 將上面的 libmysql.dll 復制到C:\Ruby192\binC:\Ruby192\lib或任何你的 lib 和 bin 所在的位置。
  3. 跑:
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.5"'

祝你好運。

如果仍然出現錯誤,請交叉檢查安裝步驟 -

http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

大多數用戶在按照描述的步驟安裝 mysql2 gem 的地方。

接受的答案對我不起作用,其他 2 也沒有。但是,MG 對 Ritesh 鏈接的評論對我有用。 我必須指定版本 0.2.6,並包含參數 --platform=ruby。 (注意:我還必須下載 MySQL 的“noinstall”版本才能獲得 /lib/opt)

這是我在 Windows 上安裝 gem 的方法

gem install mysql2 -v 0.2.6 -- --platform=ruby --with-mysql-lib=C:\Ruby192\MySQL\lib\opt --with-mysql-dir=C:\Ruby192\MySQL

我知道該線程與 Windows 有關,但我在 Linux 上搜索相同的問題並通過安裝 lib“libmysqlclient-dev”修復它

我在 64 位 Windows 7 下使用 MySQL 5.6 遇到了類似的問題。這里給出的主要解決方案有效。 (kobalz 建議的僅復制 dll 的解決方案不起作用。不知道為什么它適用於 kobalz 但不適用於我!)

然后我遇到了這篇文章中描述的另一個問題:

mysql2 gem 為錯誤的 mysql 客戶端庫編譯

那里描述的解決方案避免了下載完整的 32 位 MySQL 並修復了這兩個問題。 本質上,下載 mysql 連接器(下載量要小得多)並使用它來編譯 mysql2 gem。 如帖子中所述,您必須下載完全正確的版本。 就我而言:

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

然后如上所述將 lib\libmysql.dll 文件從那里復制到 Ruby bin 目錄中。

我將連接器放入 c:\mysql-connector-c-noinstall-6.0.2-win32

所以構建和安裝 gem 的命令是:

gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib" --with-mysql-include="c:\mysql-connector-c -noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"

然后,當我運行 rake 進行遷移時,我遇到了更多問題,但那是因為我一直在使用 mysql gem(不是 mysql2)並且我忘記更新我的 database.yml。 使用 mysql2 gem,它需要說:

開發:適配器:mysql2

而不是

開發:適配器:mysql

一旦您弄清楚了,這很明顯,但是我收到的錯誤消息與我之前收到的錯誤消息相似,因此看起來我的 gem 仍然有問題。

這個為我工作了 MariaDB 5.5 安裝:

gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\包括\mysql"'

使用以下命令構建本機擴展:'--with-mysql-lib="c:\Program Files (x86)\Maria DB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5 \包括\mys ql"'

如果您計划使用 Ruby x64,請務必使用 x64 MariaDB 包。 當然,不要忘記將 C:\Program Files (x86)\MariaDB 5.5\lib\libmysql.dll 復制到 Z4A8A08F09D37B737956649038408Bbin 中我的案例3:\Ruby3:\Ruby5

這對我有用 windows 8 64bit 並使用 ruby 64bit

下載並安裝 MYSQL 服務器 5.6 64bit

然后運行命令:

gem install mysql2 -v '0.3.16' -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files \MySQL\MySQL 服務器 5.6\include"'

希望這可以幫助

將位於 MySQL 安裝的 bin 目錄中的 libmysql.dll 復制到 Ruby 安裝的 bin 目錄中。 我的位於 C:\Program Files\MySQL 和 C:\Ruby。

暫無
暫無

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

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