在Mac Lion上使用rvm和ruby 1.9.3构建mysql2 gem的错误

far*_*adf 3 ruby rvm mysql2 osx-lion

为了在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.
Run Code Online (Sandbox Code Playgroud)
        /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
Run Code Online (Sandbox Code Playgroud)

当我查看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 */
Run Code Online (Sandbox Code Playgroud)

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

gui*_*ido 15

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

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

这解决了这个问题gem install mysql2.

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


col*_*ain 5

安装rails时安装MySQL.我尝试用rvm安装它并没有用.

看看这篇文章它应该可以帮助你安装mysql

如果失败了,这是另一个解决方案.两者都对我有用.