Rails 安装 mysql2 gem 时出问题, *** extconf.rb failed ***

levan · 2012年05月03日 · 最后由 lebao 回复于 2015年11月03日 · 23022 次阅读
Using haml (3.1.4) 
Using jquery-rails (2.0.2) 
Using kaminari (0.13.0) 
Using kgio (2.7.4) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
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... yes
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
        --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=/Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
        --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 /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
Levan:rabel-1.2 qwxwj$ gem install mysql2 -v '0.3.11'
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        /Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
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... yes
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
        --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=/Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
        --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 /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/ext/mysql2/gem_make.out



sudo apt-get install libmysqlclient-dev

安装 rails 环境的时候没安装依赖的 mysql 开发库和头文件,类似问题可以先发到 stackoverflow

#1 楼 @Rei 通过路径信息,我觉得楼主用的是 Mac brew install mysql

@lgn21st $ brew install mysql Error: You must `brew link cmake' before mysql can be installed

呃,感谢各位的回复.看完先.

@geekontheway 在 stackoverflow 找不到对应的答案 #2 发的是 linux 的. 能告诉我怎么解决么?

#5 楼 @Levan 既然 brew 都告诉你 Error: You must `brew link cmake' before mysql can be installed,那就先照做再看看

@AlphaLiu
Levan:rabel-1.2 qwxwj$ brew link cmake Linking /usr/local/Cellar/cmake/2.8.7... ln: ctest: Permission denied Error: Could not create symlink: /usr/local/bin/ctest.

#7 楼 @Levan 你装好 mysql 没

#9 楼 @Levan 用 sudo brew link cmake 试试看,我装 mysql 是没遇到这种问题的...只能给点建议...

@AlphaLiu Levan:~ qwxwj$ sudo brew link cmake Password: Cowardly refusing to `sudo brew link'

#13 楼 @Levan 解决了没有?我上次安装的时候也碰到,无奈,重装。。

@ruby_sky 没有....在 stackoverflow 上搜,都是 linux 的解决方式 请问怎么个重装法?

#12 楼 @Levan 先安装好 mysql 了啊,不然要 mysql2 gem 干嘛

@geekontheway Levan:rabel-1.2 qwxwj$ gem install mysql Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension.

/Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 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... yes 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 --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=/Users/qwxwj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby --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 /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql-2.8.1 for inspection. Results logged to /Users/qwxwj/.rvm/gems/ruby-1.9.2-p290/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

#12 楼 @Levan MySQL 都没装,这一步是前提~ 。没有 MySQL 及它的 dev 包(即头文件和库文件等),你不可能把这个 native gem 编译过。 错误信息已经告诉你了: probably lack of necessary libraries and/or headers.

你得从错误信息中分析原因呢。

你可以从这里http://dev.mysql.com/downloads/mysql/ 下载一个合适的 dmg 文件先把 MySQL 装上。

@skandhas 明白了..打扰了,感谢~

#18 楼 @skandhas 貌似我安装好 mysql-server mysql-client 后,再 gem install mysql,一样挂掉。 #15 楼 @Levan 我直接重装系统。老实说,对 Linux 了解的少,真有点麻烦。真得完整的学一下问题,不然都不能在最快时间内判断是什么 error.

#20 楼 @ruby_sky 你得需要 MySQL 的 dev 包。说白了就是编译这个 native gem 需要用到的 MySQL 提供的头文件,库文件等。没有这些,依然编译不过。

如果是 Mac 系统可以直接下载 dmg 包或者 brew install mysql > 配置 mysql 环境变量 > 启动 mysql > gem install mysql2

#17 楼 @Levan 如果是 rails3 请安装 mysql2, gem install mysql2

我用的是 Ubuntu Desktop 12.04 LTS,同样出现这个问题。 #2 楼 @lidashuang StackOverflow 给出的方法果然有效,搞定! sudo apt-get install libmysql-ruby libmysqlclient-dev

#1 楼 @Rei window 下应该怎么办

#25 楼 @new_birld 不知道,我没在 windows 下开发过。

#26 楼 @Rei 同样的问题,谢谢一楼

#25 楼 @new_birld window 下你解决了吗

最近也在学习 ruby on rails,on window74 /64 尝试了一下 gem install mysql 问题。 1:安装 devkit 2:安装 mysql2 时要制定 -- witch-mysql-dir 之前一直指到了数据库的安装路径 gem install mysql2 -- '--with-mysql-dir="D:\Program Files (x86)\MySQL\MySQL Server 5.5"‘ 怎么整都是个错误。 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.

原来是指错位置了,需要指到 connector 的路径 没有就下一个 3:正确的写法: gem install mysql2 -- --with-mysql-dir=F:\downloadfromInt ernet\mysql-connector-c-6.1.5-winx64

4:hava fun.

二楼给的答案很赞

需要 登录 后方可回复, 如果你还没有账号请 注册新账号