mysql2 gem Can't build native extensions

本秂侑毒 提交于 2019-12-19 02:29:25

问题


Our intern's computer is having problems installing the mysql2 gem. We just upgraded his computer from OS X 10.6 to 10.8 (Mountain Lion). I have tried installing mysql through homebrew and through the 64 bit DMG installer. I also tried symlinking to the dev tools (as pointed out here: Not able to install some gems after mountain lion upgrade). We have Xcode (4.4) installed and the command line tools installed. We tried a reboot after installing the command line tools.

This is his PATH declaration from ~/.bashrc:

PATH=/usr/local/bin:$PATH:$HOME/.rvm/bin:/usr/local/mysql/bin # Add RVM to PATH for scripting

Symlink:

Diego-Blantons-MacBook-Pro-3:~ lmrunner07$ sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Password:

Try to install 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

I've removed the homebrew installed mysql as well as the launch agent. Also rm -rf the gem directory (Users/lmrunner07/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11)


回答1:


I solved this by:

  1. Installing homebrew ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go) (check out their website for useage http://mxcl.github.com/homebrew/)
  2. Following these instructions http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion
  3. Reinstalling mysql with homebrew brew install mysql. (I tried installing mysql by follow these instructions http://erictarn.com/post/28269453881/how-i-installed-mysql-rvm-ruby-and-rails-on-mountain but i ran into issues later so i would recommend reinstalling mysql with homebrew.)
  4. Reinstalling rvm and rails and the gems for my project (which included mysql2)

Note: When I tried to build I had a library issue, Library not loaded: libmysqlclient.18.dylib, which was fixed by running sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib (refer to Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem if you get the same issue.)




回答2:


Have you tried:

gem install mysql2 --with-mysql-config=/usr/lib64/mysql/mysql_config

Replace the /usr/lib64/mysql/mysql_config with the location of your mysql config.




回答3:


Unfortunately the install process is very segmented and it's difficult to isolate what your problem might be without looking at your steps overall.

Without knowing more about your install steps, here are a few notes I followed that got me to a stable Rails Mountain Lion development box (again, apologies that this isn't more specific).

  1. Instructions for RVM, Ruby: moncefbelyamani.com

    Note: There were certainly steps here that I took via suggestions from brew doctor and 'rvm requirements' I've NEVER taken in previous setups.

    Notes like:

    • Xcode 4.3+ only use ruby-1.9.3-p125+ (and telling me if I had compilation issues to downgrade to Xcode 4.1)
    • Using brew install autoconf automake apple-gcc42
    • Using brew tap homebrew/dupes
    • And others...
  2. Rails specific Instructions: railsapps.github.com

  3. For mysql (skipping to the mysql part of the install: coolestguyplanettech.com

Note: I did the optional step: ... in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path... as I've found doing so can help during builds, etc (some scripts assume...)

Here, I tried to simply create a new rails app with the default database being mysql (which brought down mysql2 via bundler). From there - I tried to do a test app with a quick scaffold - and mysql2 barfed.

From there I hit an error 'Library not loaded: libmysqlclient.16.dylib' and as noted here: stackoverflow awesomeness I added this line to my .profile: export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

MY PATH included rails and ruby explicitly: /Users/gabriel/.rvm/gems/ruby-1.9.3-p194@rails327/bin:/Users/gabriel/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/gabriel/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/gabriel/.rvm/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/usr/sbin:/opt/X11/bin:

Hopefully, these resources will provide some additional help.




回答4:


I was able to get it to compile by running: PATH=/bin:/usr/bin:/opt/mysql5_64/bin gem install mysql2 Where mysql5_64 I downloaded the latest 64bit version of mysql and extracted there. Leaving my already installed mysql databases intact.




回答5:


I was able to fix this by implode-ing rvm and installing Homebrew's ruby. Then, the mysql2 gem installed just fine.

This isn't the first problem like this that I've run into with rvm. I don't think I'll be using it again.




回答6:


I had this successfully work on OSX Yosemite:

sudo port install mysql56
gem install mysql2 -- --with-mysql-config=/opt/local/lib/mysql56/bin/mysql_config


来源:https://stackoverflow.com/questions/11693360/mysql2-gem-cant-build-native-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!