在Mac Lion上构建mysql2 gem的错误w / rvm&红宝石1.9.3

时间:2012-02-07 01:10:19

标签: ruby osx-lion rvm mysql2

为了在Mac上构建ruby 1.9,我必须安装gcc 4.6。 Rails和一堆其他宝石很好。安装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标志。任何人都知道提供这些编译选项的位置,所以我可以删除此标志?或任何其他解决方案....谢谢

4 个答案:

答案 0 :(得分:15)

我尝试了这里发布的所有解决方案,但并不幸运。我通过自制程序重新安装了几次mysql但仍然没有运气。然后我遇到了一个带有解决方案的博客文章。

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

这解决了gem install mysql2的问题。

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

答案 1 :(得分:5)

在安装rails时安装MySQL。我尝试用rvm安装它并且它不起作用。

查看此article它可以帮助您安装mysql

如果失败,那么另一个solution。两者都对我有用。

答案 2 :(得分:3)

好吧,因为你生活在边缘...... -arch标志应该是-m64而不是现在......所以你需要更新你的mysql_config来反映这种变化,例如:在我的第128行替换:

-arch x86_64

-m64

然后,

gem install mysql2 

答案 3 :(得分:-3)

构建gem原生扩展失败不是关于gem依赖关系,而是关于应用程序没有完全安装。

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

sudo apt-get install libmysql-ruby libmysqlclient-dev