mysql2 gem无法构建本机扩展

Tyl*_*itt 7 macos gem ruby-on-rails mysql2

我们的实习生的计算机在安装mysql2 gem时遇到问题.我们刚刚将他的计算机从OS X 10.6升级到10.8(Mountain Lion).我尝试通过自制软件和64位DMG安装程序安装mysql.我也尝试了对开发工具的符号化(如这里所指出的:在山狮升级后无法安装一些宝石).我们安装了Xcode(4.4)并安装了命令行工具.我们在安装命令行工具后尝试重新启动.

这是他的PATH宣言~/.bashrc:

PATH=/usr/local/bin:$PATH:$HOME/.rvm/bin:/usr/local/mysql/bin # Add RVM to PATH for scripting
Run Code Online (Sandbox Code Playgroud)

符号链接:

Diego-Blantons-MacBook-Pro-3:~ lmrunner07$ sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Password:
Run Code Online (Sandbox Code Playgroud)

尝试安装gem:

Diego-Blantons-MacBook-Pro-3:~ lmrunner07$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

        /Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

make
compiling client.c
In file included from /Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby.h:32,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:105: error: size of array ‘ruby_check_sizeof_long’ is negative
/Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:109: error: size of array ‘ruby_check_sizeof_voidp’ is negative
In file included from /Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/intern.h:34,
                 from /Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:1382,
                 from /Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby.h:32,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/Users/lmrunner07/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/st.h:67: error: size of array ‘st_check_for_sizeof_st_index_t’ is negative
client.c: In function ‘rb_raise_mysql2_error’:
client.c:98: warning: ISO C90 forbids mixed declarations and code
client.c: In function ‘rb_mysql_client_socket’:
client.c:590: warning: ISO C90 forbids mixed declarations and code
make: *** [client.o] Error 1


Gem files will remain installed in /Users/lmrunner07/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/lmrunner07/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
Run Code Online (Sandbox Code Playgroud)

我已经删除了自制软件安装的mysql以及启动代理.还有rm -rfgem目录(Users/lmrunner07/.rvm/gems/ruby​​-1.9.3-p194/gems/mysql2-0.3.11)

Har*_*rro 5

我解决了这个问题:

  1. 安装自制软件ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go) (查看他们的网站使用http://mxcl.github.com/homebrew/)
  2. 遵循这些说明http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion
  3. 用homebrew重新安装mysql brew install mysql.(我尝试按照这些说明安装mysql http://erictarn.com/post/28269453881/how-i-installed-mysql-rvm-ruby-and-rails-on-mountain但我后来遇到了问题所以我会推荐用homebrew重新安装mysql.)
  4. 为我的项目重新安装rvm和rails以及gem(包括mysql2)

注意:当我尝试构建时,我有一个库问题,Library not loaded: libmysqlclient.18.dylib这是通过运行修复的sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib(参考库未加载:libmysqlclient.16.dylib错误尝试在OS X 10.6上使用mysql2 gem运行'rails server'如果你得到同样的问题.)