# Getting started with the C API

**URL:** <https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419>\
**Category:** Ruby\
**Created:** [February 13, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419 "2010-02-13T16:26:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/1 "2010-02-13T16:26:21Z")

</div>

Greets,

I’ve been teaching myself Ruby using David Black’s book, “The  
Well-Grounded Rubyist”. 5 chapters in or so, things are going well.  
However, things would be going even better if I was able to get  
started on the project that’s motivating my course of study: there’s a  
C library I’d like to write Ruby bindings for.

The Black book, while appropriate in pace and tone for an experienced  
programmer, doesn’t cover any sort of Ruby C API. The pickaxe book  
does, but before I go and buy a copy of that, I’d like to know if  
those pickaxe chapters are really the canonical reference. That seems  
weird.

What I’m looking for is the analogue to these pages:

[perlxstut - Tutorial for writing XSUBs - Perldoc Browser](http://perldoc.perl.org/perlxstut.html)  
[Python/C API Reference Manual — Python v3.1.5 documentation](http://docs.python.org/3.1/c-api/index.html)  
[Oracle Java Technologies | Oracle](http://java.sun.com/docs/books/jni/html/jniTOC.html)

From what I can tell, the closest thing Ruby has to that is a raw  
Doxygen dump…

[http://www.ruby-doc.org/doxygen/current/](http://www.ruby-doc.org/doxygen/current/)

… but that’s not much better than just spelunking the source code,  
because it doesn’t give you any idea where to get started.

I know the first edition of the pickaxe book is online, but I don’t  
like to waste time learning from dated materials.

Where should I be looking?

Marvin H.

---

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 5:00pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/2 "2010-02-13T17:00:18Z")

</div>

On 13/2/2010 11:25 PM, Marvin H. wrote:

> 

Even if you don’t learn from it, the PickAxe Edition 1 Online will give  
you an idea of the kind of coverage you can expect in the PickAxe later  
editions. When I get the chance later, I’ll write back to let you know  
what is actually in the later edition. I think I did buy the book.

Cheers,  
Mohit.  
13/2/2010 | 11:57 PM.

---

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/3 "2010-02-13T17:12:36Z")

</div>

On Sat, Feb 13, 2010 at 10:25, Marvin H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> does, but before I go and buy a copy of that, I’d like to know if  
> Doxygen dump…
> 
> Marvin H.

If you download the Ruby source, there’s a file called README.EXT  
which gives a pretty good, detailed treatment of the Ruby C API.  
Better than anything I’ve seen online. Here it is in the Ruby SVN:  
[http://svn.ruby-lang.org/repos/ruby/branches/ruby\_1\_8/README.EXT](http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/README.EXT)

This article on Ruby Inside gives you a quick primer on using mkmf to  
build a Makefile so you can start playing around with it:  
[http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html](http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html)

---

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 10:55pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/4 "2010-02-13T22:55:33Z")

</div>

On Sun, Feb 14, 2010 at 01:11:42AM +0900, Mat B. wrote:

> If you download the Ruby source, there’s a file called README.EXT  
> which gives a pretty good, detailed treatment of the Ruby C API.

That’s exactly the kind of thing I was looking for. On its own, it’s  
much more useful than the Doxygen dump – but it also makes the  
Doxygen dump itself more useful.

For what it’s worth, I think that README should be given greater  
prominence,  
as I was unable to discover such an important document despite some  
fairly  
diligent web searching before asking for help here.

> Better than anything I’ve seen online.

I agree.

Marvin H.

---

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 5:26pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/5 "2010-02-13T17:26:03Z")

</div>

Basically you can use anything that enlists the API for ruby extensions,  
I had a hard time figuring all  
out when embedding ruby into my window manager (subtle) and writing the  
C extension:

Here are some of my favorite links beside the pickaxe:  
[http://www.eqqon.com/index.php/Ruby/Ruby\_V1.9\_C\_Extension](http://www.eqqon.com/index.php/Ruby/Ruby_V1.9_C_Extension)

> **[Ruby to C, a couple snippets](https://macournoyer.wordpress.com/2008/04/16/ruby-to-c-a-couple-snippets/)**
>
> As you might already know, the Ruby interpreter you’re (probably) using (the one at ruby-lang.org) know as MRI, for Matz Ruby Interpreter, is written in C. The VM is entirely written in C and…

[ruby embedded into c++](http://metaeditor.sourceforge.net/embed/) (For embedding, outdated but  
still helpful)

And for building stuff:  
[http://ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html](http://ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html)

Many other things need to be checked in the ruby doxygen or even worse  
in the source code for stuff  
like this:

Wbr,

Christoph

> **[Setup gems load path in embedded ruby - Subforge](http://subforge.org/blogs/show/1)**
>
> Subforge - where subtle development meets subtler users

---- On Sat, 13 Feb 2010 16:25:46 +0100 Marvin H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote ----

---

<div class="post-metadata">

**Author:** ![startrekcafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@startrekcafe](https://www.ruby-forum.com/u/startrekcafe)\
**Post date:** [February 13, 2010, 10:57pm UTC](https://www.ruby-forum.com/t/getting-started-with-the-c-api/183419/6 "2010-02-13T22:57:53Z")

</div>

On Sun, Feb 14, 2010 at 01:25:30AM +0900, Christoph K. wrote:

> Here are some of my favorite links beside the pickaxe:  
> [Ruby/Ruby V1.9 C Extension - eqqon](http://www.eqqon.com/index.php/Ruby/Ruby_V1.9_C_Extension)

Ah, that’s the README, html-ified. Curious that [ruby-lang.org](http://ruby-lang.org) doesn’t  
give it  
greater visibility.

> And for building stuff:  
> [http://ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html](http://ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html)

I think I’m going to need Rake, as the build process for this library is  
very  
involved. The Perl bindings use Module::Build, the pure-Perl successor  
to  
ExtUtils::MakeMaker, beause doing complicated stuff with MakeMaker is a  
nightmare. I’m expecting to need something analogous for the Ruby  
bindings.

I also intend to publish a gem later. It seems like [docs.rubygems.org](http://docs.rubygems.org)  
is a  
good place to start, though it references a non-existent  
“DeveloperGuide”  
(sigh).

```
http://docs.rubygems.org/read/chapter/5#page18

```

Also, this…

```
http://rubyforge.org/docman/view.php/5/460/faq.html

```

## … and there are two books which have a chapter or two on creating gems

both apparently out of date:

[http://www.amazon.com/Practical-Ruby-Gems-David-Berube/dp/1590598113](http://www.amazon.com/Practical-Ruby-Gems-David-Berube/dp/1590598113)  
[http://www.amazon.com/Cookbook-Cookbooks-OReilly-Lucas-Carlson/dp/0596523696/](http://www.amazon.com/Cookbook-Cookbooks-OReilly-Lucas-Carlson/dp/0596523696/)

> Many other things need to be checked in the ruby doxygen or even worse in  
> the source code for stuff like this:
> 
> Wbr,

Hmm… that’s pretty confusing, all right. 😉

Marvin H.
