【发布时间】:2013-03-14 07:11:44
【问题描述】:
rails server 命令抛出此错误。
C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load
such file -- mysql2/2.0/mysql2 (LoadError)
我在 Windows XP 机器上使用来自 RubyInstaller 的 Ruby 2.0.0。
我知道是什么问题,但我不知道如何解决。问题是mysql2-0.3.11-x86-mingw32 gem 中没有任何2.0/ 目录。这是 rails 安装的 gem 作为 Gemfile 的依赖项:
GEM
remote: https://rubygems.org/
specs:
... many gems here
mysql2 (0.3.11-x86-mingw32)
... many gems here
DEPENDENCIES
...
mysql2
...
这就是 mysql2.rb 文件中的内容:
# C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\mysql2.rb
RUBY_VERSION =~ /(\d+.\d+)/
require "mysql2/#{$1}/mysql2" # <<-- this is that #2 line that throws an error
很明显,它采用当前的 Ruby 版本号并将其用作路径段以到达某个 mysql2 文件。实际上它是mysql2.so 文件。当我使用 Ruby 2.0.0 时,路径段是 2.0:
mysql2/2.0/mysql2
好的,现在让我们看看mysql2-0.3.11-x86-mingw32 gem 的目录是什么样子的:
dir: C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\
没有任何2.0/ 目录。
我知道关于 libmysql.dll 的问题。我在我的C:\Ruby200\bin 中有它。没用。
我从 RubyInstaller 的创建者那里读到了这个答案https://stackoverflow.com/a/5368767/1114926。我试过但没有帮助。它适用于Ruby 1.9.3,因为有1.9/ 目录。但它不适用于Ruby 2.0.0。
如何解决?
UPD 1:
感谢您的answer。我试过了。不幸的是我有ERROR: Failed to build gem native extension. 错误:
C:\>gem install mysql2 --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby200/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... *** 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:/Ruby200/bin/ruby
C:/Ruby200/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed to generate an executable file. (Runtim
eError)
You have to install development tools first.
... other code follows here...
上面写着:
您必须先安装开发工具。
但是我已经安装了完整的 DevKit,RubyInstaller 会安装它。无法理解它还需要什么。
我已经向mysql2 GitHub 页面https://github.com/brianmario/mysql2/issues/364 发布了一个问题。还没有答案。
【问题讨论】:
标签: ruby-on-rails-3 mysql2 ruby-2.0