How to install the mysql gem on Solaris with OpenCSW
Hey Google! Over here!
OK. This is a source of some trouble, it would seem. This is what worked for me, using the OpenCSW version of ruby and gcc. I hope it helps someone else!
UPDATE After a bit of discussion on the opencsw-users mailing list, it turns out that there’s a much easier way to do it:
# export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/csw/bin:/usr/ccs/bin/
# pkg-get -i ruby rubydev rubygems
# gem install mysql -- --with-mysql-dir=/opt/csw/mysql5
installs in one go. Read on if you want the hard way to do it :-)
Right; let’s go: Become root, make sure /opt/SUNWspro/bin isn’t in your path, install the ruby packages, and try it:
# export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/csw/bin:/usr/ccs/bin/
# pkg-get -i ruby rubydev rubygems
# gem install mysql -- --with-mysql-config=/opt/csw/bin/mysql_config
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/csw/bin/ruby extconf.rb --with-mysql-config=/opt/csw/bin/mysql_config
checking for mysql_ssl_set()... no
checking for mysql.h... yes
gcc: language target=386 not recognized
gcc: language target=386 not recognized
gcc: conftest.c: linker input file unused because linking not done
creating Makefile
...many more lines of FAIL...
OK. now we need to go and hack the makefile a bit. There are 3 problems with it: - There’s a bogus ‘-xtarget=386’ parameter which gcc doesn’t understand
- There’s a bogus ‘-mt’ parameter which only makes sense on HP-UX, apparently
- The makefile doesn’t specify a runtime path for libmysqlclient.so. This foxed me for ages, because I hadn’t realised that the -L parameter to gcc only affects how libraries are located when they’re linked. If you want to tell the OS where to find the libraries when it runs the app, you need to use -R as well.
Note that you can also fix that last issue by setting LD_LIBRARY_PATH, or using crle(1) to add mysql’s lib dir to the system’s search path. But LD_LIBRARY_PATH is doing it wrong, and crle is really only needed if you were going to redistribute onto other machines with OpenCSW installed somewhere non-standard. But if you’ve managed to get OpenCSW to install anywhere other that /opt/csw then, frankly, you don’t need to read this; you know it all already.
So…
# cd /opt/csw/lib/ruby/gems/1.8/gems/mysql-2.7
# vi Makefile
... and change this
CPPFLAGS = -DHAVE_MYSQL_H -I/opt/csw/include -D_FILE_OFFSET_BITS=64 -I/opt/csw/include -I/opt/csw/mysql5/include/mysql -mt -D_FORTEC_ -xtarget=386
CXXFLAGS = $(CFLAGS)
ldflags = -L. -L/opt/csw/gcc4/lib/. -m32 -march=i386 -R /opt/csw/gcc4/lib -L/opt/csw/lib
...to this…
CPPFLAGS = -DHAVE_MYSQL_H -I/opt/csw/include -D_FILE_OFFSET_BITS=64 -I/opt/csw/include -I/opt/csw/mysql5/include/mysql -D_FORTEC_
CXXFLAGS = $(CFLAGS)
ldflags = -L. -L/opt/csw/gcc4/lib/. -m32 -march=i386 -R /opt/csw/gcc4/lib -L/opt/csw/lib -R /opt/csw/mysql5/lib/mysql
now run ‘make’, and verify that everything’s found when you run ‘ldd’
# make
/opt/csw/gcc4/bin/gcc -I. -I. -I/opt/csw/lib/ruby/1.8/i386-solaris2.8 -I. -DHAVE_MYSQL_H -I/opt/csw/include -D_FILE_OFFSET_BITS=64 -I/opt/csw/include -I/opt/csw/mysql5/include/mysql -D_FORTEC_ -fPIC -mtune=i686 -O2 -pipe -m32 -march=i386 -I/opt/csw/include -fPIC -c mysql.c
/opt/csw/gcc4/bin/gcc -shared -o mysql.so mysql.o -L. -L/opt/csw/lib -Wl,-R/opt/csw/lib -L. -L/opt/csw/gcc4/lib/. -m32 -march=i386 -R /opt/csw/gcc4/lib -L/opt/csw/lib -R /opt/csw/mysql5/lib/mysql -Wl,-R -Wl,/opt/csw/lib -L/opt/csw/lib -lruby -L/opt/csw/lib/32 -L/opt/csw/mysql5/lib/mysql -lmysqlclient -lz -lposix4 -lresolv -lc -lgen -lsocket -lnsl -lm -lrt -lpthread -ldl -lcrypt -lm -lc
# ldd mysql.so
libruby.so.1 => /opt/csw/lib/libruby.so.1
libmysqlclient.so.15 => /opt/csw/mysql5/lib/mysql/libmysqlclient.so.15
libz.so => /opt/csw/lib/libz.so
... etc... should be no 'File not found' messages.
Good! now we have a library that shoud work, we just need to let ‘gem’ do it’s magic and package it:
# gem install mysql -- --with-mysql-config=/opt/csw/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed
Installing ri documentation for mysql-2.7...
Installing RDoc documentation for mysql-2.7...
... and that seems to work. Hurrah! Now, how on earth am I going to get that into a puppet manifest?
Chris May
Loading…
LS
Thank you so much for this how-to. You saved me from pulling out my hair.
29 May 2009, 20:31
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.