Tim, the Enchanter

What manner of man are you that can summon up code without C# or Java?

Tuesday, November 30, 2010

 

Building MySQL multiarch (32/64 bit) client libraries on OS X

Getting the mysql gem to build can be a pain. Especially if you have installed the 64-bit version of mysql and are using a 32-bit version of ruby

You can check the build arch of an executable/library via the file command, such as:

$ file `which ruby`
/Users/timcharper/Developer/.rvm/rubies/ruby-1.8.6-p383/bin/ruby: Mach-O executable i386
$ file /usr/local/mysql/lib/libmysqlclient.dylib 
/usr/local/mysql/lib/libmysqlclient.dylib: Mach-O 64-bit dynamically linked shared library x86_64

See how those disagree? If you're using homebrew (which you should be!), you can build the client libs/tools only (universal style) as follows:

brew install mysql --client-only --universal

Then, to install the gem, you need to pass some fancy flags to get the mysql gem to link against your new libraries:

HOMEBREW_PREFIX=/usr/local # if your prefix differs, modify this line

gem install mysql -- --with-opt-include=$HOMEBREW_PREFIX/include/mysql/ --with-opt-lib=$HOMEBREW_PREFIX/lib/mysql --without-mysql-config

Your gem should build with no errors, and your new shiny universal mysql client libraries should serve you well in the future if you use both 32-bit and 64-bit rubies.


Archives

March 2008   April 2008   May 2008   June 2008   July 2008   August 2008   October 2008   November 2008   February 2009   June 2009   December 2009   January 2010   February 2010   May 2010   June 2010   November 2010  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]