我们尝试了这个 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.
最佳答案
Wrote an update关于如何做到这一点(在我们不得不做很多之后):
- 下载MYSQL C-Connector Library (仅限 32 位)
- 解压缩到“无空格”路径(例如
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安装失败的原因
希望这对您有所帮助!
关于mysql2 gem 无法在 Windows 7 上安装 : failed to build gem native extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21720624/