How to build native Ruby gems on OS X - step by step guide

The most important step:

  • copy ruby-c-extension-examples/ThirdParty/lib/mac/2.0/Ruby.framework/Versions/2.0/libruby.2.0.0.dylib
    to ~/.rvm/rubies/ruby-2.0.0-p247/lib/ overwriting the original file. This needs to be done, because the version of Ruby which SketchUp uses is modified and the libraries have to be linked against this exact version. Otherwise you’ll get a BugSplat when SketchUp tries to load the library. This took me quite some time to figure out.

You are now ready to build Ruby gems with native extensions, e.g. yajl-ruby:

  • gem install yajl-ruby
  • copy ~/.rvm/gems/ruby-2.0.0-p247/gems/yajl-ruby-1.2.1/lib/*
    to your plugin’s library folder where SketchUp Ruby can find it. (Make sure it’s in $LOAD_PATH)

I hope this guide will help other developers.

If you’re distributing your plugin make sure to read Cannot install ruby gem in OSX - #25 by Rojj as well and modify the gems to bring them into your own namespace to avoid potential conflicts with other plugins.

(sorry, I had to split the post because I’m not allowed to put more than two links into a post)