juretta.com

Ruby: Installing Ruby MySQL driver on Intel Macs

October 13, 2006
Tags: Gems MySQL Ruby

Installing the native MySQL-Driver for Ruby on my MacBook Pro (Mac OS X 10.4.8) resulted in the following error after running
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql.

[...]
Building native extensions.  This could take a while...
mysql.c: In function Init_mysql:
mysql.c:2015: error: ulong undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)

It seems that ulong hasn't been declared in mysql.c You've got to add #define ulong unsigned long to mysql.c before you can compile the sources on a intel based mac.

I created a small patch file which you can use if you like (i assume that you have MySQL installed in /usr/local/mysql and that your Ruby Gem INSTALLATION DIRECTORY installation is /usr/local/lib/ruby/gems/1.8 - you can check this running gem environment).

# fetch patch file
cd /tmp; 
curl -O http://download.juretta.com/ruby/mac-install/\
intel-mac-mysql-gem.patch

# Assuming that Ruby Gems is located in /usr/local ...
cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7

# Makefile
sudo ruby extconf.rb install mysql -- \
--with-mysql-dir=/usr/local/mysql/

# Backup
sudo cp mysql.c mysql.c-orig

# Patch mysql.c
sudo patch mysql.c /tmp/intel-mac-mysql-gem.patch

# Make
sudo make
# Install
sudo make install

For your convenience there is shell script that builds the native mysql gem including the patch.
Just run

macbook:~ stefan$ curl http://download.juretta.com/ruby/mac-install/\
fix-mysql-gem-intel-mac.sh | /bin/bash

You must provide your superuser password. !Please look at http://download.juretta.com/ruby/mac-install/fix-mysql-gem-intel-mac.sh before you run the script! It might do evil... (it won't though)


blog comments powered by Disqus

About

juretta.com is the personal workspace of Stefan Saasen. More about this site can be found in the „About“ section.

Share!

Latest links  RSS  

More...