具有本机扩展的MySQL2错误:无法构建gem本机扩展.(宝石::安装:: ExtensionBuildError)

roo*_*ler 20 rubygems ruby-on-rails

我正在尝试为Ruby Enterprise Edition安装gem mysql2.我收到的错误是:

    Installing mysql2 (0.2.7) with native extensions /Users/rookieRails/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/installer.rb:551:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/vinayashrestha/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... 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
    --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
Run Code Online (Sandbox Code Playgroud)

有谁知道我应该使用哪些配置选项,或者我需要做些什么才能解决这个问题?

小智 53

试试这个,它对我有用:

sudo apt-get install libmysql-ruby libmysqlclient-dev
Run Code Online (Sandbox Code Playgroud)


Alt*_*gos 31

请注意,如果您使用的是rvm,请不要安装,libmysql-ruby因为它与Ubuntu Ruby版本有关.只是把sudo apt-get install libmysqlclient-dev它,它会工作


小智 6

在我的情况下,只有取消链接符号链接并在brew中重新安装mysql有助于:

brew unlink mysql
brew cleanup
brew install mysql
gem install mysql2
Run Code Online (Sandbox Code Playgroud)


roo*_*ler 4

我意识到我没有安装 mySQL,我最近升级到 Lion,并且忘记安装 mySQL。不过,在那之后我遇到了一些问题,我按照这篇文章来设置一切:

http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard

现在一切正常。