4

我使用来自http://dev.mysql.com/downloads/mysql的安装程序安装了 MySQL 服务器。然后,如几个指南中所述,我想使用以下命令安装 mysql gem。

sudo gem install mysql

这不起作用并给出以下输出。

Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql/
checking for mysql_ssl_set()... *** 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/luzi/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
    --with-mysql-config
    --without-mysql-config
/Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:894:in `block in have_func'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:893:in `have_func'
    from extconf.rb:45:in `<main>'


Gem files will remain installed in /Users/luzi/.rvm/gems/ruby-1.9.3-p429/gems/mysql-2.9.1 for inspection.
Results logged to /Users/luzi/.rvm/gems/ruby-1.9.3-p429/gems/mysql-2.9.1/ext/mysql_api/gem_make.out

我多次重新安装了 ruby​​ 1.9.3。XCode 命令行实用程序也已安装。我也用自制软件安装了 mysql 服务器(没有带任何东西)。

我还为上面的命令尝试了一些选项,比如--with-mysql-dir=/usr/local/mysqland --with-mysql-config=/usr/local/mysql/bin/mysql_config。传入标志 ( sudo env ARCHFLAGS="-arch x86_64" gem install mysql) 也无济于事。

更新

我也尝试了mysql2 gem,出现同样的错误,可能是因为mysql2 gem 依赖于mysql gem。

更新 2

内容mkmf.log

"/opt/local/bin/gcc-apple-4.2 -o conftest -I/Users/luzi/.rvm/rubies/ruby-1.9.3-p429/include/ruby-1.9.1/x86_64-darwin12.4.0 -I/Users/luzi/.rvm/rubies/ruby-1.9.3-p429/include/ruby-1.9.1/ruby/backward -I/Users/luzi/.rvm/rubies/ruby-1.9.3-p429/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/opt/local/include -I/usr/local/mysql/include  -Wno-null-conversion -Os -g -fno-strict-aliasing -arch x86_64  -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe conftest.c  -L. -L/Users/luzi/.rvm/rubies/ruby-1.9.3-p429/lib -L/opt/local/lib -L. -L/usr/local/lib -L/opt/local/lib     -L/usr/local/mysql/lib -lmysqlclient  -lruby.1.9.1  -lpthread -ldl -lobjc "
cc1: error: unrecognized command line option "-Wno-null-conversion"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */
4

3 回答 3

9

问题在这里解释:http ://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html 。简而言之:

/usr/local/mysql/bin/mysql_config在第 120 行附近更改文件

cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
于 2013-06-25T15:55:45.553 回答
1

问题不在于宝石本身。您缺少 XCode(从 AppStore 安装),也可能缺少https://github.com/kennethreitz/osx-gcc-installer,因为您的错误日志显示:

您必须先安装开发工具。

为了更好地解释该问题,请查看 mkmf.log 以及错误日志所建议的内容。

于 2013-06-25T14:10:04.983 回答
0

我在 Fedora 21 上安装 mysql2psql 时遇到问题,我通过从 mysql.org 下载 mysql 源 tar.gz 并将 --with-mysql-config 设置到这个提取的目录到 bin/mysql_config 文件来解决它

gem install mysql2psql -- --with-mysql-config=/pathtodownloadedsource/mysql../bin/mysql_config

于 2014-12-18T17:44:17.093 回答