简体   繁体   English

在Windows上为ruby 2.0.0安装mysql2 gem时出错

[英]Error during install of mysql2 gem for ruby 2.0.0 on Windows

I'm trying to install the mysql2 gem for Ruby 2.0.0. 我正在尝试为Ruby 2.0.0安装mysql2 gem。

I tried following the instructions at http://rorguide.blogspot.hk/2011/03/installing-mysql2-gem-on-ruby-192-and.html , but was not successful. 我尝试按照http://rorguide.blogspot.hk/2011/03/installing-mysql2-gem-on-ruby-192-and.html上的说明进行操作,但未成功。 Given the error message below, can anyone help me resolve this error? 鉴于以下错误消息,有人可以帮助我解决此错误吗?

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:/xampp/Ruby200-x64ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... 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:/xampp/Ruby200-x64ruby
        --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-libmysqllib
        --without-libmysqllib


Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.
3.6 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.6/ext/mysql2/ge
m_make.out

My ruby was downloaded from here: 我的红宝石是从这里下载的:

http://rubyinstaller.org/ http://rubyinstaller.org/

EDIT 编辑

C:\xampp\Ruby200-x64\lib\ruby\gems\2.0.0>gem install mysql2 -- '--with-mysql-lib
="c:\xampp\mysql\lib" --with-mysql-include="c:\xampp\mysql\include" --with-mysql
-config="c:/xampp/mysql/bin/mysql_config.exe"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="c:\xampp\mysql\lib" --with-m
ysql-include="c:\xampp\mysql\include" --with-mysql-config="c:/xampp/mysql/bin/my
sql_config.exe"'
This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/xampp/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-lib="c:\xampp\mysq
l\lib" --with-mysql-include="c:\xampp\mysql\include" --with-mysql-config="c:/xam
pp/mysql/bin/mysql_config.exe"
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:/xampp/Ruby200-x64/bin/ruby
C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed
 to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:516:in `try_link0'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:531:in `try_link'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:717:in `try_func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:1001:in `block in have_
func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:892:in `block in checki
ng_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block (2 levels
) in postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block in postpo
ne'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:333:in `postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:891:in `checking_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:1000:in `have_func'
        from extconf.rb:9:in `<main>'


Gem files will remain installed in C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems
/mysql2-0.3.11 for inspection.
Results logged to C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/ex
t/mysql2/gem_make.out

C:\xampp\Ruby200-x64\lib\ruby\gems\2.0.0>gem install mysql2 -- '--with-mysql-lib
="c:/xampp/mysql/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql
-config="c:/xampp/mysql/bin/mysql_config.exe"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="c:/xampp/mysql/lib" --with-m
ysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xampp/mysql/bin/my
sql_config.exe"'
This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/xampp/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-lib="c:/xampp/mysq
l/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xam
pp/mysql/bin/mysql_config.exe"
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:/xampp/Ruby200-x64/bin/ruby
C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed
 to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:516:in `try_link0'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:531:in `try_link'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:717:in `try_func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:1001:in `block in have_
func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:892:in `block in checki
ng_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block (2 levels
) in postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block in postpo
ne'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:333:in `postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:891:in `checking_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:1000:in `have_func'
        from extconf.rb:9:in `<main>'


Gem files will remain installed in C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems
/mysql2-0.3.11 for inspection.
Results logged to C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/ex
t/mysql2/gem_make.out

C:\xampp\Ruby200-x64\lib\ruby\gems\2.0.0>gem install mysql -- '--with-mysql-lib=
"c:/xampp/mysql/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql-
config="c:/xampp/mysql/bin/mysql_config.exe"'
Fetching: mysql-2.9.1.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="c:/xampp/mysql/lib" --with-m
ysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xampp/mysql/bin/my
sql_config.exe"'
This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

    C:/xampp/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-lib="c:/xampp/mysq
l/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xam
pp/mysql/bin/mysql_config.exe"
checking for main() in -llibmysql... *** 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:/xampp/Ruby200-x64/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include=${mysql-dir}/include
        --with-mysql-lib=${mysql-dir}/
        --with-libmysqllib
        --without-libmysqllib
C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed
 to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:516:in `try_link0'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:531:in `try_link'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:717:in `try_func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:947:in `block in have_l
ibrary'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:892:in `block in checki
ng_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block (2 levels
) in postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block in postpo
ne'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:333:in `postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:891:in `checking_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:942:in `have_library'
        from extconf.rb:27:in `<main>'


Gem files will remain installed in C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems
/mysql-2.9.1 for inspection.
Results logged to C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql-2.9.1/ext/
mysql_api/gem_make.out

C:\xampp\Ruby200-x64\lib\ruby\gems\2.0.0>gem install mysql -- '--with-mysql-lib=
"c:/xampp/mysql/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql-
config="c:/xampp/mysql/bin/mysql_config"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="c:/xampp/mysql/lib" --with-m
ysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xampp/mysql/bin/my
sql_config"'
This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

    C:/xampp/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-lib="c:/xampp/mysq
l/lib" --with-mysql-include="c:/xampp/mysql/include" --with-mysql-config="c:/xam
pp/mysql/bin/mysql_config"
checking for main() in -llibmysql... *** 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:/xampp/Ruby200-x64/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include=${mysql-dir}/include
        --with-mysql-lib=${mysql-dir}/
        --with-libmysqllib
        --without-libmysqllib
C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed
 to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:516:in `try_link0'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:531:in `try_link'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:717:in `try_func'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:947:in `block in have_l
ibrary'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:892:in `block in checki
ng_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block (2 levels
) in postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:337:in `block in postpo
ne'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:333:in `postpone'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:891:in `checking_for'
        from C:/xampp/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:942:in `have_library'
        from extconf.rb:27:in `<main>'


Gem files will remain installed in C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems
/mysql-2.9.1 for inspection.
Results logged to C:/xampp/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql-2.9.1/ext/
mysql_api/gem_make.out

C:\xampp\Ruby200-x64\lib\ruby\gems\2.0.0>
checking for main() in -llibmysql... no

you are missing libmysql-headers. 您缺少libmysql-headers。

edit: is duplicate of: Installing mysql-2.9.0 gem on Windows fails due to lack of libmysql 编辑:是重复的: 由于缺少libmysql,在Windows上安装mysql-2.9.0 gem失败

your error clearly stated that it is regarding to your Devkit So you can download devkit from 您的错误明确表明与您的Devkit有关,因此您可以从以下位置下载Devkit

http://rubyinstaller.org/downloads http://rubyinstaller.org/downloads

and follow the steps from 并遵循以下步骤

https://github.com/oneclick/rubyinstaller/wiki/Development-Kit https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

this will resolve your problem 这将解决您的问题

llibmysql error means ruby can't see libmysql.dll. llibmysql错误意味着ruby无法看到libmysql.dll。 I got the error just now, so I`ve copied libmySQL.dll to $mysqldir/lib and got another error 我刚刚收到错误,所以我已经将libmySQL.dll复制到$ mysqldir / lib并出现了另一个错误

checking for main() in -llibmysql... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.

So, now ruby can see libmysql.dll, but now it needs mysql files. 因此,现在ruby可以看到libmysql.dll,但是现在它需要mysql文件。 I launch mysql installator again and select, that I need include files. 我再次启动mysql安装程序,然后选择需要包含文件的位置。 2minutues - and I got includes directory. 2分钟-我得到包含目录。 Launch gem install mysql2.... again and got 1 gem installed . 再次启动gem install mysql2.... ,并1 gem installed1 gem installed

If like me, you have some coworker working on a rails project using Windows (in my case Windows 7). 如果像我一样,您有一些同事使用Windows(在我的情况下为Windows 7)从事Rails项目。 In order to install the gem “mysql2″ you need to specify in the command line the path to use the libraries. 为了安装gem“ mysql2”,您需要在命令行中指定使用库的路径。

Pre-requisite: Having MYSQL installed. 先决条件:已安装MYSQL。

Command line to run (replace the path by your installation path) 要运行的命令行(通过安装路径替换路径)

 gem install mysql2 — ‘–with-mysql-lib=”c:\Program Files\MySQL\MySQL Server 5.6\lib” –with-mysql-include=”c:\Program Files\MySQL\MySQL Server 5.6\include”‘

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

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