mysql2 gem无法在Windows 7上安装:无法构建gem原生扩展

时间:2014-02-12 06:46:47

标签: mysql ruby-on-rails ruby-on-rails-3 rubygems

我们尝试了这个SO post关于使用mysql2 gem更正安装错误的建议,但我们的问题仍然存在。我们还查看了其他SO帖子,例如this one,但都没有帮助。

我们在Windows 7上使用rails 3.2.12。

libmysql.dll已安装在C:\RailsInstaller\Ruby1.9.3\bin中,但已于2013年3月安装。

错误:

Using mongo_mapper (0.12.0)
Installing mysql2 (0.3.15)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
checking for ruby/thread.h... no
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.

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:/RailsInstaller/Ruby1.9.3/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-mysql-config
        --without-mysql-config
        --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-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mygcclib
        --without-mygcclib
        --with-mysqlclientlib
        --without-mysqlclientlib


Gem files will remain installed in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15
Results logged to C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/ext/mysql2/gem_m
An error occurred while installing mysql2 (0.3.15), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.15'` succeeds before bundling.

1 个答案:

答案 0 :(得分:0)

Wrote an update关于如何做到这一点(在我们不得不做很多事情之后):

  • 下载MYSQL C-Connector Library(仅限32位)
  • 解压缩到“无空格”路径(E.G C:/mysql-connector
  • 使用相对路径安装gem:
gem install mysql2 —platform=ruby — ‘—with-mysql-dir=”C:\mysql-connector-path”’
  • 将DLL添加到您的Ruby / bin文件夹(您已经完成)

<强>原因

失败的原因是因为Win 7没有安装MYSQL库,这意味着Ruby无法引用安装gem所需的文件

您需要安装正确的文件(以后可以删除)。看来你已经安装了错误的,这可能是gem无法安装的原因

希望这有帮助!