Sunday, March 21, 2010

Mac OS X Leopard installing the ruby gem eventmachine

I was having some trouble installing eventmachine (a ruby gem that needs an extension library written in C++) recently in Mac OS X Leopard. I am currently running ruby 1.8.8dev. I think, perhaps, when I compiled ruby from source, the config left out the CXX flags setting. This makes mkmf not know what C++ compiler it needs to set in the Makefiles it creates. Since there are not too many gems that have extensions written in C++ (that I know of), I never really ran into this issue. Here is how to fix this.

Edit this file inside the directory of the gem, in my case;

$ vim /usr/local/lib/ruby/gem/1.8/gem/eventmachine-0.12.11/ext/extconf.rb

Right above the last line (the last line being a call to create_makefile), insert this line:

CONFIG['CXX'] = g++

then do the same thing for this extconf.rb in the fastfilereader dir (or anywhere else in the ext dir where there might be more nested extconf.rb files.

then run this:

cd /usr/local/lib/ruby/gem/1.8/gem/eventmachine-0.12.11; rake gem:install

this should solve the issue of getting errors like this:

make: I.: Command not found
make: dynamic: Command not found

1 comment:

Pauli Price said...

Chris,

Thanks very much for posting this where I could find it on Google. You saved me from pulling much hair out, as I had no a clue what the error really was.

For the benefit of future readers who, like myself, have never looked at the contents of a extconf.rb file before, placing the CONFIG statement at the bottom of the file didn't work. Perhaps a newer version of RubyGems or eventmachine changed things. However, the fix is still to insert the missing CONFIG statement.

It worked when I added the CONFIG statement to the /darwin/ clause of the RUBY_PLATFORM case statement, as follows.

when /darwin/
# on Unix we need a g++ link, not gcc.
# Ff line contributed by Daniel Harple.
CONFIG['CXX'] = "g++"
CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')

NOTE: I also had to quote "g++".