【问题标题】:Unable to install mysql2 gem OS X Mountain Lion无法安装 mysql2 gem OS X Mountain Lion
【发布时间】:2012-08-10 08:07:55
【问题描述】:

我是 RoR 的新手,我正在尝试安装 Mysql2 -v '0.3.11'。 我有 OS X Mountain Lion,rails 3.2.6,ruby 1.9.3。

以下是我得到的错误。我到处找,什么也没找到。

$gem install mysql2 -v '0.3.11'
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

    /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/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 client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:105:37:     error: 'ruby_check_sizeof_long' declared as an array with a negative size
typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:24:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:109:38: error: 'ruby_check_sizeof_voidp' declared as an array with a negative size
typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:28:22: note: expanded from macro 'SIZEOF_VOIDP'
#define SIZEOF_VOIDP 8
                 ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:1377:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:34:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/st.h:67:45: error: 'st_check_for_sizeof_st_index_t' declared as an array with a negative size
typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:28:22: note: expanded from macro 'SIZEOF_VOIDP'
#define SIZEOF_VOIDP 8
                 ^
3 errors generated.
make: *** [client.o] Error 1


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

感谢您的帮助。

【问题讨论】:

    标签: mysql ruby-on-rails macos gem mysql2


    【解决方案1】:

    我在 mac10.10 中也遇到了相同类型的错误,并使用了以下对我有用的命令:

    1. 使用以下命令安装和升级 Homebrew:

      brew安装mysql

    2. 运行安装 Mysql gem 文件使用:

      gem install mysql2 -v '0.3.11'

    3. 运行捆绑安装

    【讨论】:

      【解决方案2】:

      您使用的是 RVM,而不是 10.8 附带的 Ruby。好的。现在,停止使用 10.8 附带的 MySQL。

      安装和更新 Homebrew。现在运行

      brew install mysql
      

      在您的项目中使用/Gemfile 来安装mysql2 gem。添加

      gem "mysql2"
      

      到您的/Gemfile。然后通过运行使用 Bundler 更新您的应用程序

      bundle install
      

      让包管理器(Homebrew 和 Bundler) 为你工作。

      这应该可以解决您遇到的问题。

      【讨论】:

      • 如果您要投反对票,请解释原因,以便改进我的回答。
      • 命令 brew install 有效,但是 rvm exec bundle install 没有。无论如何谢谢:)
      • @Francisco 直接运行bundle install 对您有用吗?好久没用rvm了,好像rvm exec或者rvm do都没有了。随意发布对问题的更合适的编辑did 对您有用。
      • 当然。命令brew install mysql 有效,bundle install 也有效。通过这些步骤,我可以成功安装 mysql2
      【解决方案3】:

      正如Deefour 所说,我必须使用 RVM。答案是他,我只是无法评论他的答案。 +1

      但是rvm exec bundle install给了我一个错误:

      rvm do bundle install 已删除,请改用 rvm 1.9.2,1.9.3 do bundle installrvm all do bundle install

      我用过 sudo rvm all do bundle install 从那时起,一切都完美无缺。

      【讨论】:

        猜你喜欢
        • 2011-11-16
        • 2012-10-21
        • 1970-01-01
        • 2013-06-17
        • 2012-08-29
        • 1970-01-01
        • 2012-07-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多