PDA

View Full Version : Ruby / Rails / MySQL problems in Fedora 4


rob
July 21st, 2005, 11:58 PM
If you are having trouble getting the mysql gem to install in Fedora 4, ie. getting this error (or similar):

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.6 for inspection.
ruby extconf.rb install mysql\nchecking 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... yes
checking for mysql_query() in -lmysqlclient... no

Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.6/gem_make.out

Then when you view gem_make.out, you get something like:

mysql.c:635: error: invalid storage class for function ‘res_free’
mysql.c:637: error: ‘res_free’ undeclared (first use in this function)
mysql.c:637: error: (Each undeclared identifier is reported only once
mysql.c:637: error: for each function it appears in.)
make: *** [mysql.o] Error 1


This error is caused by gcc 4 being used. We need to make it run gcc32 instead, which is the binary that Fedora has for gcc version 3.2.

Go ahead and run this again, just to be sure:

gem install mysql

Let command fail. Once it does, change directory to

/usr/lib/ruby/gems/1.8/gems/mysql-2.6

and run:

ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config

Then, edit Makefile in this directory and search for "i386-redhat-linux-gcc" (without the quotes). Replace it with gcc32.

Also, search for two instances of -mtune=pentium4 (or whatever CPU you use). Take the entire -mtune=cpu reference out.

Save the file, then run make. It should work fine for you!

Then, to register it with gem, run:

gem install mysql

again.

Thanks to the kind person on the the RoR wiki post (http://wiki.rubyonrails.com/rails/show/MySQL+Database+access+problem) that suggested that gcc 4 was to blame.

mrj
November 28th, 2005, 01:57 AM
If, like me, you can't even build the Makefile, edit the CC, CPP, and CFLAGS variables directly in /usr/lib/ruby/1.8/i386-linux/rbconfig.rb

Thank you for finding out the cause of the problem was related to GCC on Fedora. For me it was use of the Fedora Ruby RPMs in combination with gcc 3.4.4 compiled from source.

dogas
February 2nd, 2006, 10:10 AM
It's worth noting, after following all the directions I could find, banging my head against the wall for a few days, I came across a solution.

First I uninstalled ruby and compiled the ruby source from ruby-lang.org

Then I attempted to install the mysql gem
gem install mysql

..and was dismayed when I got the same error. After perusing mkmf.log for a while I noticed that it was looking in the wrong dir for the libs (I have a feeling the options may not be working correctly). So I did a little ln -s magic
ln -s /usr/lib/mysql/ /usr/local/lib/mysql

..then ran

ruby extconf.rb
checking for mysql_query() in -lmysqlclient... yes
checking for mysql_ssl_set()... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
creating Makefile


Success!

Not sure if it has to do with compiling ruby on my own or doing a simple ln -s to the correct lib dir (there are really a ton of variables, could be any one), but I finally got it up.

rob
February 2nd, 2006, 05:44 PM
I wish the mysql gem would search both locations, as this would fix this issue once and for all.

The symlink isn't a bad idea, however, be sure and check it from time to time after a MySQL upgrade on your system, esp. to a major version.

Then again, a recompile of the mysql gem would be necessary then anyway :)