Getting Ruby GD2 working on OSX

I installed the Ruby GD2 gem on my Mac last night and found myself getting the following error:

ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb:59:in `initialize’:RuntimeError: dlopen(libgd.2.dylib, 9): image not found

It didn’t take very long to figure out that OSX doesn’t seem to come with any version of libgd. After bouncing around with trying to get RMagick installed instead, and finding very little documentation on setting up the Ruby GD2 library, I decided to install the gd2 package via ports and reinstalled the gem with the same results. It still wasn’t finding libgd because the ports library path (/opt/local/lib) is not set in my path. I don’t set this because I want anything self-compiled to only use the Mac libraries. After some digging, I found that I could specify the path in the Ruby GD2 source.

To fix it I changed line 33 in “ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb” from:

case Config::CONFIG[‘arch’]
when /darwin/
‘libgd.2.dylib’

to:

case Config::CONFIG[‘arch’]
when /darwin/
‘/opt/local/lib/libgd.2.dylib’

It’s not the cleanest fix, but it’s good enough for development purposes. Hopefully this saves a few people from some of the circles I went through figuring this out. It does seem that this is a least a more simple fix than what’s required to get the RMagick library running on OSX.

Posted by chrisp Sun, 26 Nov 2006 20:05:00 GMT