Building the MacPorts MySQL gem on OS X

I’ve been running with the Rails MySQL adapter for a while now after failing to build the native MySQL gem under Leopard. The problem, I thought, was that I’m using the Macports MySQL, and it turns out I was right. If you attempt to build the MySQL gem and you get an error like this:

Building native extensions.  This could take a while...
ERROR:  While executing gem ...
(Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.
 
ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
 
Gem files will remain installed in
/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to
/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

All you need to is tell gem where to find to find mysql_config5 so the MySQL headers and library files can be discovered automatically. Credit to Igor Petrushenko for pointing out this shortcut in the comments.

sudo gem install mysql --\
  -with-mysql-config=`which mysql_config5`

Similarly, if you already have the MySQL gem installed you can update it using the same arguments:

sudo gem update -- \
  -with-mysql-config=`which mysql_config5`
This entry was posted in os x, ruby, tips and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. HY
    Posted October 1, 2008 at 5:17 am | Permalink

    This worked great for me and saved me a ton of time.

  2. Posted December 3, 2008 at 5:08 pm | Permalink

    Hi, all

    The only one thing, which actually works for me:

    sudo gem install mysql — –with-mysql-config=`which mysql_config5`

    Thank you,
    Sincerely,
    Igor,
    http://www.MyTaskHelper.com

  3. Posted May 17, 2009 at 12:33 pm | Permalink

    thaaanks you

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">