简体   繁体   English

Ruby mysql2 gem,无法在Windows 7上构建

[英]Ruby mysql2 gem, cannot build on Windows 7

I come from OSX where Ruby runs super flawlessly 90% of the time. 我来自OSX,Ruby在90%的情况下都能完美运行。 I haven't touched it in awhile though and happen to be working on a Windows 7 machine right now. 我已经有一段时间没有碰过它了,并且碰巧现在正在Windows 7机器上工作。 I'm trying to run a simple Ruby on Rails project but I can't seem to get past any of my database setup. 我正在尝试运行一个简单的Ruby on Rails项目,但似乎无法超越我的任何数据库设置。
I want to run on mysql but when I try to install the mysql2 gem (via bundle install or gem install mysql2 ) I get these errors: 我想在mysql上运行,但是当我尝试安装mysql2 gem(通过bundle installgem install mysql2 )时,出现以下错误:

Installing mysql2 (0.2.9) with native extensions C:/Ruby192/lib/ruby/site_ruby/1 .9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. 使用本机扩展C:/ Ruby192 / lib / ruby​​ / site_ruby / 1 .9.1 / ruby​​gems / installer.rb:533:在`build_extensions中的块中救援'中安装mysql2(0.2.9):错误:无法构建gem本机扩展。 (Gem::Installer::ExtensionBuildError) (Gem :: Installer :: ExtensionBuildError)

  C:/Ruby192/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. rb_thread_blocking_region()... * extconf.rb失败*由于某种原因(可能缺少必要的库和/或头文件)而无法创建Makefile。 Check the mkmf.log file for more details. 检查mkmf.log文件以获取更多详细信息。 You may need configuration options. 您可能需要配置选项。

I'm pretty much a complete newb when it comes to this kind of thing so if anyone has any advice, please help! 关于这种事情,我几乎是个新手,所以如果有人有任何建议,请帮忙!

To install and compile extensions sometimes you need libraries and headers of the dependencies. 要安装和编译扩展,有时您需要依赖项的库和标头。 In this case, you need MySQL headers and libraries to properly compile. 在这种情况下,您需要MySQL标头和库来正确编译。

Assuming you downloaded Ruby from RubyInstaller and also installed the Development Kit and followed it's installation instructions , to successfuly install mysql2 gem I recommend you read this answer in our Troubleshooting page : 假设您从RubyInstaller下载了Ruby,并且还安装了Development Kit并按照其安装说明进行操作 ,以成功安装mysql2 gem,建议您在我们的故障排除页面中阅读以下答案:

  1. Download MySQL Connector/C 下载MySQL Connector / C
  2. Extract into a path without spaces 提取到没有空格的路径中
  3. When installing mysql2 gem, provide the additional options ( gem install mysql2 -v 0.2.10 -- --with-mysql-include=... --with-mysql-lib... ) 在安装mysql2 gem时,提供其他选项( gem install mysql2 -v 0.2.10 -- --with-mysql-include=... --with-mysql-lib...

Provide for --with-mysql-include option the path to the include directory of MySQL Connector/C. --with-mysql-include选项include MySQL Connector / C的include目录的路径。 The same for --with-mysql-lib but this time point to lib directory. --with-mysql-lib但是这次指向lib目录。

Don't forget to copy libmysql.dll to your Ruby bin directory. 不要忘记将libmysql.dll复制到您的Ruby bin目录中。

Hope this helps. 希望这可以帮助。

The problem with native extensions on Windows is that there are two different compiler infrastructures: one based on MS VC and its Visual Studio and one based on MinGW (Minimalist GCC for Windows). Windows上本机扩展的问题在于,存在两种不同的编译器基础结构:一种基于MS VC及其Visual Studio,另一种基于MinGW(Windows的极简主义GCC)。

There are Ruby native extensions that can be compiled with any of them and other, that only support one. 有Ruby本机扩展可以与其中任何一个及其他仅支持一个的一起进行编译。 And since most of them come from some kind of Unix, chances are that mingw works better that MSVC. 而且由于它们大多数来自某种Unix,因此有可能mingw比MSVC更好。

So you may try to install mingw and use it to compile mysql gem - there is a special package called devkit , which contains a minimal necessary mingw installation which you just put inside your ruby installation. 因此,您可以尝试安装mingw并使用它来编译mysql gem-有一个名为devkit的特殊软件包,其中包含一个最小的必需mingw安装,您只需将其放入ruby安装中即可。

I had a success compiling several native extensions using devkit: eventmachine, linecache, bson-ext to name a few. 我成功地使用devkit编译了几个本机扩展:eventmachine,linecache,bson-ext等。 And within devkit you will feel much more are home :-) (coming from OSX) 在devkit中,您会感觉到更多了:-)(来自OSX)

If you have the devkit setup correct as @Tomasz mentions, please make sure you check the compatibility of mysql2 gem version with windows, I have experienced in the past for it to cause issues and had to go and install a previous version to get it working. 如果您具有@Tomasz提到的正确的devkit安装程序,请确保您检查mysql2 gem版本与Windows的兼容性,我过去曾遇到过这种问题,因此会导致问题,因此必须安装以前的版本才能使其正常运行。 Last I remember v0.2.6 was the version that supported windows. 最后,我记得v0.2.6是支持Windows的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM