Ruby: Installing Ruby MySQL driver on Intel Macs | October 13, 2006-->
October 13, 2006
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)

Maxime says: http://www.ekohe.com
Thanks for the detailed help. It solves my problem on my powerpc powerbook.
Bill says: http://brilliantcorners.org/
You truly saved my sanity. Thanks so, so much. This works like a charm, and I no longer have to look at all the “Lost connection to MySQL” error messages again.
Casper Kaandorp says:
THANKS A MILLION! I finally can get to work.
Mat says: www.matschaffer.com
claps Nice work. Now if only we could track down why this patch doesn’t get added to the rubyforge project. I suppose it’s a little more complicated to make it cross platform, but still…
Anyway, thanks a bunch! You’re a life saver!
gomez says:
thanks a lot from cologne
Daryl Wilding-McBride says:
Thanks for this script. It solved my problem on my OS X 10.4.9 PowerMac. Really appreciate the contribution.
BZ says:
I made sure /usr/local/mysql/bin was in my $PATH and then I ran this command and it resolved the same error you were having:
gem install mysql——with-mysql-config=/usr/local/mysql/bin/mysql_config