Ruby on rails 安装mysql2 gem时出错

Ruby on rails 安装mysql2 gem时出错,ruby-on-rails,gem,mysql2,Ruby On Rails,Gem,Mysql2,我正试图用MySQL建立我的RubyOnRails开发环境。我已经安装了XAMPP,所以我决定使用XAMPP的MySQL安装(因此我安装了XAMPP开发包) 现在我正在尝试安装mysql2 gem,但出现以下错误: gem install mysql2 --version 0.2.7 -- --with-mysql-dir=/Applications/XAMPP/xamppfiles/ --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mys

我正试图用MySQL建立我的RubyOnRails开发环境。我已经安装了XAMPP,所以我决定使用XAMPP的MySQL安装(因此我安装了XAMPP开发包)

现在我正在尝试安装mysql2 gem,但出现以下错误:

gem install mysql2 --version 0.2.7 -- --with-mysql-dir=/Applications/XAMPP/xamppfiles/ --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ –with-mysql-include=/Applications/XAMPP/xamppfiles/include/mysql/ --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config 
Error loading RubyGems plugin "/Library/Ruby/Gems/1.8/gems/yard-0.6.3/lib/rubygems_plugin.rb": undefined method `overwrite_accessor' for Gem::Specification:Class (NoMethodError)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-dir=/Applications/XAMPP/xamppfiles/ --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ –with-mysql-include=/Applications/XAMPP/xamppfiles/include/mysql/ --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
checking for rb_thread_blocking_region()... no
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

make
gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Applications/XAMPP/xamppfiles/include/mysql  -I/Applications/XAMPP/xamppfiles/include -L/Applications/XAMPP/xamppfiles/lib -mmacosx-version-min=10.4 -arch i386 -arch ppc   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common  -Wall -funroll-loops  -c client.c
gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Applications/XAMPP/xamppfiles/include/mysql  -I/Applications/XAMPP/xamppfiles/include -L/Applications/XAMPP/xamppfiles/lib -mmacosx-version-min=10.4 -arch i386 -arch ppc   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common  -Wall -funroll-loops  -c mysql2_ext.c
./client.h:20: warning: ‘rb_thread_blocking_region’ defined but not used
./client.h:20: warning: ‘rb_thread_blocking_region’ defined but not used
./client.h:20: warning: ‘rb_thread_blocking_region’ defined but not used
gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Applications/XAMPP/xamppfiles/include/mysql  -I/Applications/XAMPP/xamppfiles/include -L/Applications/XAMPP/xamppfiles/lib -mmacosx-version-min=10.4 -arch i386 -arch ppc   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common  -Wall -funroll-loops  -c result.c
cc -arch x86_64 -pipe -bundle -undefined dynamic_lookup -o mysql2.bundle client.o mysql2_ext.o result.o -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -L. -arch x86_64  -Wl,-rpath,/Applications/XAMPP/xamppfiles/lib    -lruby -L/Applications/XAMPP/xamppfiles/lib -I/Applications/XAMPP/xamppfiles/include -mmacosx-version-min=10.4  -L/Applications/XAMPP/xamppfiles/lib/mysql -lmysqlclient_r -lz -lm  -lpthread -ldl  
ld: -rpath can only be used when targeting Mac OS X 10.5 or later
collect2: ld returned 1 exit status
make: *** [mysql2.bundle] Error 1


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/ext/mysql2/gem_make.out
所以我认为这里的关键点是:

ld: -rpath can only be used when targeting Mac OS X 10.5 or later
我尝试将MACOSX_部署_目标设置为10.6,但没有任何变化

顺便说一下,我使用的是Mac OS X 10.6.6,所以上面的错误没有任何意义


谢谢大家!

您可以尝试以下几种可能性

  • 尝试将
    --platform=ruby
    添加到命令中。我已经看到人们声称它有帮助

    然后,您的命令应该是:

    gem install mysql2 --platform=ruby --version 0.2.7 -- --with-mysql-dir=/Applications/XAMPP/xamppfiles/ --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ –with-mysql-include=/Applications/XAMPP/xamppfiles/include/mysql/ --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
    
  • 确保您正在构建正确的体系结构。OSX10.6.x对于什么时候使用32位和什么时候使用64位非常模糊,至少据我所知

    您需要尝试构建32位和64位版本的MySQL

    最简单的方法是从下载这两个文件,并尝试根据每一个文件进行构建


  • 我不能在任何其他实现中谈论这个问题,但它在JRUBY中是已知的问题。看见