Updating MySQL Gem to 2.7

   By chris on April 19th 2007 in /dev/ruby | 521 views

While updating my installed gems this evening I ran into an issue with the mysql-2.7 gem:

ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb update
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

The solution was to explicitly tell gem where the local MySQL install is:

Sagarmatha:~ chris$ which mysql
/usr/local/mysql/bin/mysql

Sagarmatha:~ chris$ sudo gem install mysql — –with-mysql-dir=/usr/local/mysql

Caveat: Note the double -- between mysql and --with. That’s not a typo (though it may look like a single dash in this page in some browsers).

4 Responses to “Updating MySQL Gem to 2.7”

  1. Brandon responded on 04 Sep 2007 at 6:43 pm #

    It would be nice if gem would have the courtesy to tell us that it needed a location.

    P.S. Aren’t cha gonna tell us what’s with the extra –?

  2. chris responded on 05 Sep 2007 at 10:35 am #

    Quite frankly I don’t know why the extra dashes are required in there. I just stumbled upon it by accident. Bloody Unix developers… ;)

  3. Thomas Watson responded on 02 Oct 2007 at 1:57 pm #

    The double hyphens (–) tells the option parser that there is no more options on the command line. This special syntax comes from GNU getopt. Everything after ‘–’ is treated as non-options. This is useful if you want to write something on the command line that looks like an option but is not, or if it should be parsed though as an option to another program called by the one you are calling.

    The two hyphens in this particular command string is important since the gem binary must not confuse the ‘–with-mysql-dir’ option as an option for gem it self. Instead this option should be passed on to the make command called in the gem internals.

  4. chris responded on 02 Oct 2007 at 2:08 pm #

    A sound explanation. Thanks Thomas!

Trackback URI | Comments RSS

Leave a Reply