Friday, December 08, 2006

Finally Got Mysql/Postgres Gem to Install

The incantation:

gem install mysql -- --with-mysql-lib=/opt/csw/lib/mysql --with-mysql-include=/opt/csw/mysql5/include/mysql

gem install postgres -- --with-pgsql-lib=/opt/csw/postgresql/lib --with-pgsql-include=/opt/csw/postgresql/include

The reason this was tricky, is because our sysadmin guys didn't install the mysql-devel libraries. They did however install the mysql4rt (runtime) stuff. I ended up installing the devel libraries in my home directory while the sysadmin guys get around to it.

Somewhat related, is how I improperly used ruby's [mkmf] library to debug the gem installation. Each gem that needs to build C extensions, uses an extconf.rb file that runs a bunch of crap and ends up generating a Makefile. The extconf.rb file makes heavy use of ruby's [mkmf] library. Anyway, I noticed that the extconf.rb script kept bombing out during its call to: [find_library('mysqlclient', 'mysql_query', lib] where [lib = /path/to/static/lib/mysql]. This seemed odd since the [lib] var was pointing to the mysql static libraries that I installed in my home directory. So I tried using irb to isolate the problem:

irb(main):001:0> require 'mkmf'
=> true
irb(main):002:0> lib = "/path/to/static/lib/mysql"
=> "/path/to/static/lib/mysql"
irb(main):003:0> find_library('mysqlclient', 'mysql_query', lib)
=> false

WTF?

For some reason I thought that the find_library() function wanted to know the path to the static library 'libmysqlclient.a'. This is not the case, it actually wants the path to the location of the shared library 'libmysqlclient.so'. Once I figured this out, I was able build the extension and find_library() was able to find the library:

irb(main):001:0> require 'mkmf'
=> true
irb(main):006:0> lib = '/path/to/shared/lib/mysql
=> "/path/to/shared/lib/mysql"
irb(main):007:0> find_library('mysqlclient', 'mysql_query', lib)
checking for mysql_query() in -lmysqlclient... yes
=> true

No comments: