Wednesday, December 13, 2006

Uninstalling MySql on OSX

Recently I installed mysql-5 on my laptop using the .dmg installer. Later I decided that I wanted to use mysql-4 instead. Since there is no mysql uninstaller for os x, I did [rm -rf /usr/local/mysql], thinking this would do the trick. The problem, however, is now when I try to install mysql I keep getting the message "You cannot continue. There is nothing to install." After poking around a bit more I found out that you need to delete the "mysql*.pkg/" directories located in /Library/Receipts

That did the trick!

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

Tuesday, December 05, 2006

The True Meaning of libx.a Files

I don't really know C very well, so I was surpirsed (and delighted) when I finally learned what all those libx.a files are. For example, if you have mysql installed on your system, go take a look in the mysql/lib directory. You should see a bunch of files ending in .a . These are archive files containing compiled C code, basically they are the same thing as a java .jar file. Who knew?

If you want to check the contents of the arhive you can use the [nm] command. Like [nm libmysqlclient.a]

Want to know if the arhive has a specific function? [nm libmysqlclient.a | grep mysql_query]

Monday, December 04, 2006

Extracting Files from a Package on Solaris

Recently I was having trouble getting the mysql gem installed on our solaris x86 servers at work. Basically the slowaris box didn't have the mysql-client headers needed to build the native extension for the mysql gem. As a work around, while I'm waiting for the sysadmin guys to install the headers, I downloaded the mysql4devel.pkg from blastwave: http://www.blastwave.org/

Ok, now I have the package, but how the heck to I extract its contents? I'm not root nor do I have sysadmin privileges so I certainly can usd [pkgadd] and install the little booger.

After I bit of research I found that you can use [pkgtrans] to extract the files from .pkg archive.

The following extracts the contents of the .pkg archive into a tmp directory (Note: you must create the temporary directory first, then extract)

[mkdir tmp && pkgtrans mysql4devel.pkg tmp]