Updating MySQL Gem to 2.7
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/mysqlSagarmatha:~ 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).

Brandon responded on 04 Sep 2007 at 6:43 pm #
It would be nice if
gemwould have the courtesy to tell us that it needed a location.P.S. Aren’t cha gonna tell us what’s with the extra –?
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…
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.
chris responded on 02 Oct 2007 at 2:08 pm #
A sound explanation. Thanks Thomas!