gpt4 book ai didi

ruby-on-rails-3 - 错误 "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)"。在带有 Ruby 2.0.0 的 Windows XP 上

转载 作者:行者123 更新时间:2023-12-04 01:36:44 32 4
gpt4 key购买 nike

命令 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)

我用 ruby 2.0.0 来自 RubyInstaller在 Windows XP 盒子上。

我想出了什么问题,但我不知道如何解决它。问题是没有任何 2.0/ mysql2-0.3.11-x86-mingw32 中的目录 gem 。这是 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\

enter image description here

没有 2.0/目录。

我知道关于 的问题libmysql.dll .我有它在我的 C:\Ruby200\bin .它没有帮助。

我读了这个答案 https://stackoverflow.com/a/5368767/1114926来自 RubyInstaller 的创建者。我试过了,但没有帮助。它适用于 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...

它说:

You have to install development tools first.



但是我已经安装了完整的 DevKit,RubyInstaller 会安装它。不明白它还需要什么。

我已经将问题发布到 mysql2 GitHub 页面 https://github.com/brianmario/mysql2/issues/364 .还没有答案。

最佳答案

在使用 Ruby 2.0.0 和 DevKit 4.7 的 Windows 7 x64 上遇到了完全相同的问题。

以下步骤帮助了我。

  • gem uninstall mysql2

  • http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip 下载最后一个 MySQL 连接器
  • 解压到 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"'


  • 或者更短:

    gem install mysql2 --platform=ruby -- --with-opt-dir="C:\connector-6.0.2"

    关于ruby-on-rails-3 - 错误 "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)"。在带有 Ruby 2.0.0 的 Windows XP 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604058/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com