Fork me on GitHub
18 Oct 2009
Ruby C Extensions Part 1: Toolchain

Cooking up a Ruby C Extension

I've always wanted to try making a Ruby C Extension, for once because I wanted to know what was going on under Ruby's hood and then again because I wanted to see if writing for Ruby in C is as easy as writing in Ruby itself.

It, of course, is not.

But that's mainly because writing in C is a pain in the *#?!, not because the interfacing-with-Ruby part is hard to do.

Anyways, after coming up with a pure Ruby gem for wildcard matching (Joker) I thought: Hey, that would make an excellent C extension!

So I ventured out on a journey to conquer the Ruby C extension world -- or at least leave a footprint on its ground.

This article and it's followers are my idea of a map of my journey and the holes I fell in and stones I tripped over, so you won't have to.

I hope it helps someone.

First off: Getting the Right Tools

One of the most important things when developing Ruby C extensions is to get your toolset right. If you start out with none or the wrong tools, you're sooner or later going to get lost in the compiler jungle.

So you better plan ahead and have them installed.

Here's a list of what I recommend:

Great! Now run off to your nearest package manager and get them all! Meanwhile, I'll finish the next part of my little narration...

Here's how to get the gems:

gem install rake-compiler rake-tester

for valgrind and gcc, please use your OS package manager or get some binaries on the net.

Continue with Part 2!

Comments?