【问题标题】:Errors building mysql2 gem on Mac Lion w/ rvm & ruby 1.9.3在带有 rvm 和 ruby​​ 1.9.3 的 Mac Lion 上构建 mysql2 gem 时出错
【发布时间】:2012-02-28 11:52:55
【问题描述】:

为了在 mac 上构建 ruby​​ 1.9,我必须安装 gcc 4.6。 Rails 和一堆其他的 gem 构建得很好。安装 mysql 或 mysql2 让我各种心痛。

rubygems> env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.
        /Users/ff/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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.
-----
*** 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/ff/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
    --with-mysql-config


Gem files will remain installed in /Users/ff/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/ff/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

当我查看 mkmf.log 文件时,我看到:


have_header: checking for mysql.h... -------------------- no

"/opt/local/bin/gcc-mp-4.6 -E -I/Users/ff/.rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/x86_64-darwin11.2.0 -I/Users/ff/.rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/Users/ff/.rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1 -I. -I/Users/ff/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/mysql/include -Os -arch i386 -fno-common  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fno-common -pipe  conftest.c -o conftest.i"
gcc-mp-4.6: error: i386: No such file or directory
gcc-mp-4.6: error: unrecognized option '-arch'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <mysql.h>
/* end */

所以基本上似乎不支持 -arch 标志。任何人都知道这些编译选项是在哪里提供的,所以我可以删除这个标志?或任何其他解决方案....谢谢

【问题讨论】:

    标签: ruby osx-lion rvm mysql2


    【解决方案1】:

    我尝试了此处发布的所有解决方案,但并不幸运。我通过自制软件重新安装了 mysql 几次,但仍然没有运气。然后我发现了一篇包含解决方案的博客文章。

    我在/usr/local/Cellar/mysql/5.6.12/bin 中编辑了mysql_config 文件,并删除了cflagscxxflags 的W 编译器选项-Wno-null-conversion-Wno-unused-private-field

    这解决了gem install mysql2 的问题。

    参考:randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os

    【讨论】:

    • 在这个问题上花了将近 2 个小时才找到这个解决方案,cheerios:)
    • 为我工作。谢谢。
    • 尽管它没有回答使用 /usr/local/mysql 的版本的问题,但这对我有用,因为我通过自制软件安装了 MySql。
    【解决方案2】:

    在安装 Rails 时单独安装 MySQL。我尝试用 rvm 安装它,但它不起作用。

    看看这个article它应该可以帮助你安装mysql

    如果失败,这里是另一个solution。两者都为我工作。

    【讨论】:

    • 谢谢。我已经在我的系统上运行 mysql 多年了。我只是从 ruby​​ 1.8.x 升级到 1.9 并且 mysql2 驱动程序有问题。我想我可以从头开始重新安装 mysql 看看是否有帮助。
    【解决方案3】:

    好吧,既然您生活在边缘... -arch 标志现在应该是 -m64... 所以您可能需要更新您的 mysql_config 以反映该更改,例如在我的第 128 行替换:

    -arch x86_64
    

    -m64
    

    那么,

    gem install mysql2 
    

    【讨论】:

    • mysql_config在哪里?
    • 谢谢!这有助于我在 Snow Leopard 上升级 Ruby 1.8.7->1.9.3。我什至不用重新安装mysql,就用了:env ARCHFLAGS="-m64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
    【解决方案4】:

    构建 gem 原生扩展失败与 gem 依赖无关,而是与应用程序未完全安装有关。

    我遇到了同样的问题,这应该可以解决问题:

    sudo apt-get install libmysql-ruby libmysqlclient-dev

    【讨论】:

    • 那是 ubuntu 的。他要的是 MacOs
    • osx 不支持apt-get
    猜你喜欢
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多