【问题标题】:Installing mysql-2.9.0 gem on Windows fails due to lack of libmysql由于缺少 libmysql,在 Windows 上安装 mysql-2.9.0 gem 失败
【发布时间】:2012-11-28 11:48:13
【问题描述】:

我正在尝试在 Windows Server 2003 上安装 Redmine 2.1.4。要使其正常工作,我需要安装 activerecord-mysql-adapter gem,而后者似乎又依赖于 mysql-2.9.0.gem。我已经从rubygems 下载了后者并执行了:

gem install mysql-2.9.0.gem

给出以下输出:

C:\>gem install mysql-2.9.0.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql-2.9.0.gem:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for main() in -llibmysql... 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.

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:/Ruby193/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0/ext/mysql_api/gem_make.out

我猜,一种可能是我缺少 MySQL C 连接器库。我已经从http://dev.mysql.com/downloads/connector/c/ 下载了mysql-connector-c-6.0.2-win32.msimysql-connector-c-6.0.2-win32-vs2005.msi,但是两个安装程序都退出了:

我也尝试将C:\Program Files\MySQL\MySQL Server 5.1\lib\debug\libmysql.dll复制到C:\Ruby193\bin,但也没有解决mysql-2.9.0.gem安装问题。

我还能尝试什么?

编辑

从我发现的日志中,Ruby 正在寻找 $RUBY_HOME\lib,而不是 $RUBY_HOME\bin 下的库,如问题中提到的一些来源中所发现的。所以将 libmysql 从 $MySQL_HOME\lib 移动到 $RUBY_HOME\lib 有一点帮助,但是现在 Ruby 找不到其他一些库和头文件。所以我猜,我需要使用如下选项:

C:\>gem install mysql-2.9.0.gem --platform=ruby --with-opt-lib="C:/Program Files/MySQL/MySQL Server 5.1/lib" --with-opt-include="C:/Program Files/MySQL/MySQL Server 5.1/include"

这也不起作用(可能是因为路径中有空格)。

【问题讨论】:

  • mkmf.log 说什么?在我的 exp 中,你要么 gem install mysql,要么 mysql2。
  • 我不知道这些日志 - 谢谢 - 编辑了我的问题。

标签: ruby mysql-connector


【解决方案1】:

尝试使用来自http://dev.mysql.com/downloads/connector/c/ 的没有安装程序版本的连接器,并在根文件夹或没有任何空间的文件夹路径中提取内容,然后尝试安装 mysql gem

示例

gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

【讨论】:

  • 除了从提供的链接下载连接器之外,该命令行对我有用: gem install mysql --platform=ruby -- --with-mysql-lib=c:\mysql_connector\lib --with-mysql-include=C:\mysql_connector\include(我重命名了我提取存档内容的目录的名称)
  • 我刚刚使用 MySQL Connector 6.1.3 成功安装了它,使用以下命令: gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/connector- 6.1.3
【解决方案2】:

我已经发布了带有 rubyx86-mingw32 预编译二进制文件的 mysql gem 版本 2.9.0。

如果你让RubyGems判断合适的平台,它会自动为你安装x86-mingw32平台gem,这样可以避免编译过程。

安装后,它将显示一组说明,指示您下载 MySQL Connector/C 并将其 DLL 放置在正确的位置:

C:\Users\Luis>gem install mysql
Fetching: mysql-2.9.0-x86-mingw32.gem (100%)

======================================================================================================

  You've installed the binary version of mysql.
  It was built using MySQL Connector/C version 6.0.2.
  It's recommended to use the exact same version to avoid potential issues.

  At the time of building this gem, the necessary DLL files where available
  in the following URL:

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

  You can put the lib\libmysql.dll available in this package to your Ruby bin directory.
  E.g. C:\Ruby\bin

======================================================================================================

Successfully installed mysql-2.9.0-x86-mingw32
1 gem installed

如果您只需要连接到已经运行的 MySQL 版本,则无需下载或安装 MySQL。

RubyGems 和 Bundler 都会自动检测正确的平台并安装正确的预编译二进制文件,而无需您自己编译。

如果您使用代理,请使用gem install--http-proxy 参数(请参阅帮助)或设置HTTP_PROXY 环境变量。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2018-11-27
    相关资源
    最近更新 更多