3

我从 RuyInstaller 安装了 Ruby 2.0.0 和 DevKit。创建新项目时出现错误消息:

rails new testtest -d mysql

..... a lot of output here ........

Installing mysql2 (0.3.14)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
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 mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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.

如何安装依赖项以使此 gem 没有任何错误?

4

2 回答 2

9

您需要 MySQL 32 位(或MySQL 连接器 Cmysql2在 Windows 上编译 gem 编译(即使您使用的是 64 位版本的操作系统)。

按着这些次序:

  1. 下载 MySQL 服务器 32 位 .zip 文件(或者MySQL 连接器 C也可以)
  2. 复制libmysql.dll%RUBY_HOME%\bin(或简单地将 MySQL 32 位lib目录添加到 PATH)
  3. --with-mysql-lib使用和--with-mysql-include选项安装 mysql2 gem

    gem install mysql2 -- '--with-mysql-lib="c:\path\to\32-bit-MySQL-Server\lib\opt" --with-mysql-include="c:\\path\to\32-bit-MySQL-Server\include"'
    
于 2013-11-13T05:52:58.330 回答
0

这是我的故事。尝试使用 devkit 在 Windows 7 上安装 mysql2 gem。首先,您需要安装连接器库和头文件。不要使用默认文件夹“Program Files”,gem 无法包含带空格的文件夹。我已经通过 subst X:\ "C:\Program File\Mysql Connector 6 C\" 替换连接器文件夹,然后使用以下 cmd: gem install mysql2 -- --with-mysql-dir=X:\ 然后意识到我'正在使用带有 32 位 ruby​​ 的 64 位连接器库。重新安装连接器。然后gem就安装成功了。但是运行失败,抱怨缺少mysql dll。所以,我把 libmysql.dll 和 *.lib 放到了 ruby​​\bin 文件夹中。毕竟这能够使用mysql2 gem。

于 2014-02-17T14:54:07.333 回答