2

I am trying to create a C extension for ruby. I am very new to development and have only just became familiar with Ruby, so it im really lost.

I have looked at "How to create a C Extension in Ruby in under five minutes" and it makes sense. The problem is that I dont know what program(s) to use to compile the C code and the Ruby code. I have been using text documents for my Ruby programming, so I have never needed to compile them.

If I want to make a C extension (following the model previously mentioned) what IDE do I use, and what file format do I compile to? Also, where do I place the Ruby file and the C compiled file? And finally, will a simple notepad editor work for this Ruby development? Remember, I am new to programming in general, so these questions may appear naive.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
user1546594
  • 539
  • 1
  • 4
  • 4
  • What do you use for Ruby now? – ChiefTwoPencils Aug 13 '12 at 20:15
  • There are a lot of loosely related questions here. You should definitely learn C properly before you even start with the Ruby C API. Once you've done so, the [Ruby C API SO wiki page](http://stackoverflow.com/tags/ruby-c-api/info) is useful. – Andrew Marshall Aug 14 '12 at 01:40

2 Answers2

0

Before creating C extensions for Ruby, you really should be familiar with C programming in general. Once you've learned the fundamentals of C, you should be able to easily follow a Ruby extension tutorial.

As for how to learn C, that depends on your platform and what resources you have available.

To answer your specific questions, you can use any C compiler, and you usually compile the source to a .so file, which Ruby can require directly (so the location of the file doesn't really matter).

Max
  • 21,123
  • 5
  • 49
  • 71
0

The first step for me was getting a build environment for my particular platform and that was the DevKit for Windows. Now that is dependent on what your OS is. As long as you know some Ruby then I would suggest learning how to use Rake. There are tasks that you may run from your Rakefile that will compile your C extension. You should get familiar with setting up the directory structure. I think that I have lots of info on a github repo that I maintain for reference.

Ruby_C_extensions

The one that may help you the most is under stree folder. The readme has links to the tutorial.

Enjoy!

Douglas G. Allen
  • 2,203
  • 21
  • 20