# Ruby C/C++ Interface

**URL:** <https://rubytalk.org/t/ruby-c-c-interface/30249>\
**Category:** ruby-talk\
**Created:** [23 August 2006 07:50 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249 "2006-08-23T07:50:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kandlinger](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kandlinger](https://rubytalk.org/u/Kandlinger)\
**Post date:** [23 August 2006 07:50 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/1 "2006-08-23T07:50:15Z")

</div>

Hello, I am currently developing a webshop which uses a c/c++ shared  
object/dynamic link library for some functions. Currently I am  
evaluating which technology I should use. As I've got a completely  
free choice I was thinking of Java Server Faces or Ruby on Rails. I  
never used Ruby on Rails before, so my question is: How big is the  
support of Ruby to access a c/c++ shared object/dynamic link library of  
which i only got a c/c++ header file ?

---

<div class="post-metadata">

**Author:** ![Dido\_Sevilla](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dido\_Sevilla](https://rubytalk.org/u/Dido_Sevilla)\
**Post date:** [23 August 2006 08:04 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/2 "2006-08-23T08:04:27Z")

</div>

Actually, it's incredibly easy to write C extensions for Ruby,  
compared to many other languages. The file README.EXT in the Ruby  
source distribution explains how this can be done, and compared to  
languages such as Perl (which uses a small domain-specific language)  
and Java (JNI is also messy), it is quite simple. Which is why too  
many people don't consider Ruby's general slowness that big a problem;  
it is easy enough to write C extensions for speed-critical portions of  
the code.

> **···**
>
> On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:
> 
> > Hello, I am currently developing a webshop which uses a c/c++ shared  
> > object/dynamic link library for some functions. Currently I am  
> > evaluating which technology I should use. As I've got a completely  
> > free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > never used Ruby on Rails before, so my question is: How big is the  
> > support of Ruby to access a c/c++ shared object/dynamic link library of  
> > which i only got a c/c++ header file ?

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [23 August 2006 10:31 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/3 "2006-08-23T10:31:27Z")

</div>

For an example of this, feel free to look at the source code for the  
EventMachine library. The main library was written in C++ and not designed  
for Ruby. There is a small wrapper of pure C calls above the C++-based  
functionality, and the C wrapper is also not designed for Ruby. And then  
there is a standard Ruby extension which only massages data to and from  
Ruby-land and calls functions in the C wrapper, which it accesses only by  
#including a small header file. We had originally tried dlopen and SWIG and  
they were very painful. This approach has been fine.

> **···**
>
> On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:
> 
> > Hello, I am currently developing a webshop which uses a c/c++ shared  
> > object/dynamic link library for some functions. Currently I am  
> > evaluating which technology I should use. As I've got a completely  
> > free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > never used Ruby on Rails before, so my question is: How big is the  
> > support of Ruby to access a c/c++ shared object/dynamic link library of  
> > which i only got a c/c++ header file ?

---

<div class="post-metadata">

**Author:** ![Charles\_Nutter](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/charles_nutter/32/2567_2.png) [@Charles\_Nutter](https://rubytalk.org/u/Charles_Nutter)\
**Post date:** [23 August 2006 19:25 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/4 "2006-08-23T19:25:43Z")

</div>

I would say this, from a Java perspective: accessing existing C/C++ code or  
writing C/C++ extensions for Ruby is quite a bit easier than writing similar  
code for Java using JNI. That said, JNI protects your Java application a bit  
better from external bugs, though you can still crash it nicely.

> **···**
>
> On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:
> 
> > Hello, I am currently developing a webshop which uses a c/c++ shared  
> > object/dynamic link library for some functions. Currently I am  
> > evaluating which technology I should use. As I've got a completely  
> > free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > never used Ruby on Rails before, so my question is: How big is the  
> > support of Ruby to access a c/c++ shared object/dynamic link library of  
> > which i only got a c/c++ header file ?
> 
> --  
> Contribute to RubySpec! @ [Welcome to headius.com](http://www.headius.com/rubyspec)  
> Charles Oliver Nutter @ headius.blogspot.com  
> Ruby User @ ruby.mn  
> JRuby Developer @ [www.jruby.org](http://www.jruby.org)  
> Application Architect @ [www.ventera.com](http://www.ventera.com)

---

<div class="post-metadata">

**Author:** ![Kandlinger](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kandlinger](https://rubytalk.org/u/Kandlinger)\
**Post date:** [23 August 2006 08:25 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/5 "2006-08-23T08:25:17Z")

</div>

> Actually, it's incredibly easy to write C extensions for Ruby,

Thanks for your help, but the problem in my application is:  
1. It is c++ code  
2. The c++ code is already written (and not designed for Ruby)

Does this matter or is it still easy to use this in Ruby ?

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [23 August 2006 09:42 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/6 "2006-08-23T09:42:43Z")

</div>

You may also try SWIG, that will generate the extension for you from  
your header file (sometimes it needs little tweaking).

[http://www.swig.org/](http://www.swig.org/)

> **···**
>
> On 8/23/06, Dido Sevilla \<dido.sevilla@gmail.com\> wrote:
> 
> > On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:  
> > \> Hello, I am currently developing a webshop which uses a c/c++ shared  
> > \> object/dynamic link library for some functions. Currently I am  
> > \> evaluating which technology I should use. As I've got a completely  
> > \> free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > \> never used Ruby on Rails before, so my question is: How big is the  
> > \> support of Ruby to access a c/c++ shared object/dynamic link library of  
> > \> which i only got a c/c++ header file ?
> > 
> > Actually, it's incredibly easy to write C extensions for Ruby,  
> > compared to many other languages. The file README.EXT in the Ruby  
> > source distribution explains how this can be done, and compared to  
> > languages such as Perl (which uses a small domain-specific language)  
> > and Java (JNI is also messy), it is quite simple. Which is why too  
> > many people don't consider Ruby's general slowness that big a problem;  
> > it is easy enough to write C extensions for speed-critical portions of  
> > the code.

---

<div class="post-metadata">

**Author:** ![ryan.raaum](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@ryan.raaum](https://rubytalk.org/u/ryan.raaum)\
**Post date:** [23 August 2006 12:30 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/7 "2006-08-23T12:30:10Z")

</div>

Dido Sevilla wrote:

> **···**
>
> > On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:  
> > \> Hello, I am currently developing a webshop which uses a c/c++ shared  
> > \> object/dynamic link library for some functions. Currently I am  
> > \> evaluating which technology I should use. As I've got a completely  
> > \> free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > \> never used Ruby on Rails before, so my question is: How big is the  
> > \> support of Ruby to access a c/c++ shared object/dynamic link library of  
> > \> which i only got a c/c++ header file ?
> > 
> > Actually, it's incredibly easy to write C extensions for Ruby,  
> > compared to many other languages. The file README.EXT in the Ruby  
> > source distribution explains how this can be done, and compared to  
> > languages such as Perl (which uses a small domain-specific language)  
> > and Java (JNI is also messy), it is quite simple. Which is why too  
> > many people don't consider Ruby's general slowness that big a problem;  
> > it is easy enough to write C extensions for speed-critical portions of  
> > the code.
> 
> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> x. It is significantly harder to extend ruby on windows than on one of  
> the unixy systems.

---

<div class="post-metadata">

**Author:** ![Dido\_Sevilla](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dido\_Sevilla](https://rubytalk.org/u/Dido_Sevilla)\
**Post date:** [23 August 2006 09:06 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/8 "2006-08-23T09:06:24Z")

</div>

> Thanks for your help, but the problem in my application is:  
> 1. It is c++ code

It doesn't matter. C++ code can be used within a Ruby extension.

> 2. The c++ code is already written (and not designed for Ruby)

Doesn't matter either. There are literally hundreds of extension  
libraries around there, some of which interface with C++ code that was  
never designed with Ruby in mind (e.g. the Fox GUI toolkit, and the  
FXRuby extension).

> **···**
>
> On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:

---

<div class="post-metadata">

**Author:** ![Robin\_Stocker1](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@Robin\_Stocker1](https://rubytalk.org/u/Robin_Stocker1)\
**Post date:** [23 August 2006 13:31 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/9 "2006-08-23T13:31:40Z")

</div>

Jan Svitok wrote:

> You may also try SWIG, that will generate the extension for you from  
> your header file (sometimes it needs little tweaking).
> 
> [http://www.swig.org/](http://www.swig.org/)

For an example of this, you can take a look at my id3lib-ruby project [1], where I use the id3lib C++ library from Ruby through bindings generated with SWIG. It was very easy to create the SWIG interface file and it works perfectly.

[1] [http://rubyforge.org/projects/id3lib-ruby](http://rubyforge.org/projects/id3lib-ruby)

---

<div class="post-metadata">

**Author:** ![M\_Edward\_Ed\_Borasky1](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@M\_Edward\_Ed\_Borasky1](https://rubytalk.org/u/M_Edward_Ed_Borasky1)\
**Post date:** [23 August 2006 13:44 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/10 "2006-08-23T13:44:18Z")

</div>

Jan Svitok wrote:

> You may also try SWIG, that will generate the extension for you from  
> your header file (sometimes it needs little tweaking).
> 
> [http://www.swig.org/](http://www.swig.org/)
> 
> > \> Hello, I am currently developing a webshop which uses a c/c++ shared  
> > \> object/dynamic link library for some functions. Currently I am  
> > \> evaluating which technology I should use. As I've got a completely  
> > \> free choice I was thinking of Java Server Faces or Ruby on Rails. I  
> > \> never used Ruby on Rails before, so my question is: How big is the  
> > \> support of Ruby to access a c/c++ shared object/dynamic link library of  
> > \> which i only got a c/c++ header file ?
> > 
> > Actually, it's incredibly easy to write C extensions for Ruby,  
> > compared to many other languages. The file README.EXT in the Ruby  
> > source distribution explains how this can be done, and compared to  
> > languages such as Perl (which uses a small domain-specific language)  
> > and Java (JNI is also messy), it is quite simple. Which is why too  
> > many people don't consider Ruby's general slowness that big a problem;  
> > it is easy enough to write C extensions for speed-critical portions of  
> > the code.

I'm just now getting to learn SWIG in general and the Ruby interface in  
particular. The Ruby/C interfacing is fairly simple, but C++ is a good  
bit more complicated. First off, make sure you have the latest  
development version of SWIG -- I have swig-1.3.29. The documentation is  
all in HTML; they haven't put up a PDF yet. The web site is  
[http://www.swig.org](http://www.swig.org).

One thing SWIG lets you do is develop code in C/C++, and then make  
interface modules that support \*all\* the scripting languages SWIG  
supports! That is, you write one set of C/C++ code and one set of  
interface modules, and SWIG builds the wrapper code for all the  
scripting languages!. Right now, they support guile, Java, Lua, mono,  
Ocaml, Perl, PHP, Python, Ruby, Tcl/Tk and Pike.

> **···**
>
> > On 8/23/06, Dido Sevilla \<dido.sevilla@gmail.com\> wrote:
> > 
> > > On 8/23/06, kandlinger@gmx.de \<kandlinger@gmx.de\> wrote:

---

<div class="post-metadata">

**Author:** ![Patrick\_Hurley1](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Patrick\_Hurley1](https://rubytalk.org/u/Patrick_Hurley1)\
**Post date:** [23 August 2006 14:42 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/11 "2006-08-23T14:42:02Z")

</div>

Not really. It is significantly harder to build libraries designed for  
unixy systems under windows than on those unixy systems. But the Ruby  
interface to C/C++ is pretty much identical between platforms. Why do  
you say it is harder?

pth

> **···**
>
> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > Also, it is important to ask if you are on windows or linux/bsd/mac os  
> > x. It is significantly harder to extend ruby on windows than on one of  
> > the unixy systems.

---

<div class="post-metadata">

**Author:** ![Leslie\_Viljoen1](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Leslie\_Viljoen1](https://rubytalk.org/u/Leslie_Viljoen1)\
**Post date:** [23 August 2006 09:40 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/12 "2006-08-23T09:40:25Z")

</div>

It's easy to use C++ code in Ruby extensions, but you still need to  
know some C++ and you should look out for some gotchas.

You may want to look at some past posts about this:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/100255](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/100255)

Google for "ruby c++ extensions" to get an idea of what you are up  
against - it seems that C++ is a bit harder than straight C.

Les

---

<div class="post-metadata">

**Author:** ![ryan.raaum](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@ryan.raaum](https://rubytalk.org/u/ryan.raaum)\
**Post date:** [23 August 2006 19:05 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/13 "2006-08-23T19:05:07Z")

</div>

Patrick Hurley wrote:

> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> \> x. It is significantly harder to extend ruby on windows than on one of  
> \> the unixy systems.
> 
> Not really. It is significantly harder to build libraries designed for  
> unixy systems under windows than on those unixy systems. But the Ruby  
> interface to C/C++ is pretty much identical between platforms. Why do  
> you say it is harder?

Because ruby is unix focussed. All the core ruby developers are unix  
people. The ruby toolchain is a unix-oriented toolchain (see the  
recent 100+ message thread about ruby on windows).

To build on windows, one must either build ruby from scratch using  
mingw (a topic of some contention and basically a unix toolset for  
windows) or have vc6, which is less than readily available if you don't  
already have it. Ruby does not build easily in currently available  
microsoft tools.

Starting from scratch, on a vanilla unix system, anyone with reasonable  
unix and c knowledge can build ruby and a (minimal) custom extension in  
well under an hour.

Starting from scratch, on a vanilla windows system, I would be amazed  
if a windows guru could build ruby and a custom extension in under a  
full working day.

> **···**
>
> > On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > pth

---

<div class="post-metadata">

**Author:** ![ryan.raaum](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@ryan.raaum](https://rubytalk.org/u/ryan.raaum)\
**Post date:** [23 August 2006 19:10 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/14 "2006-08-23T19:10:07Z")

</div>

> Patrick Hurley wrote:  
> \> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> \> \> x. It is significantly harder to extend ruby on windows than on one of  
> \> \> the unixy systems.  
> \>  
> \> Not really. It is significantly harder to build libraries designed for  
> \> unixy systems under windows than on those unixy systems. But the Ruby  
> \> interface to C/C++ is pretty much identical between platforms. Why do  
> \> you say it is harder?
> 
> Because ruby is unix focussed. All the core ruby developers are unix  
> people. The ruby toolchain is a unix-oriented toolchain (see the  
> recent 100+ message thread about ruby on windows).
> 
> To build on windows, one must either build ruby from scratch using  
> mingw (a topic of some contention and basically a unix toolset for  
> windows) or have vc6, which is less than readily available if you don't  
> already have it. Ruby does not build easily in currently available  
> microsoft tools.
> 
> Starting from scratch, on a vanilla unix system, anyone with reasonable  
> unix and c knowledge can build ruby and a (minimal) custom extension in  
> well under an hour.
> 
> Starting from scratch, on a vanilla windows system, I would be amazed  
> if a windows guru could build ruby and a custom extension in under a  
> full working day.

Qualifying my own post. Using mingw - slightly longer than on unix  
allowing for the time needed to install mingw. Using microsoft tools -  
much more difficult.

> **···**
>
> ryan.raaum@gmail.com wrote:
> 
> > \> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > \>  
> > \> pth

---

<div class="post-metadata">

**Author:** ![Patrick\_Hurley1](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Patrick\_Hurley1](https://rubytalk.org/u/Patrick_Hurley1)\
**Post date:** [23 August 2006 23:33 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/15 "2006-08-23T23:33:47Z")

</div>

I won't argue that building Ruby on Windows is somewhat difficult  
(well gathering the unixy tool chain for Windows takes some patience  
and then the build is pretty easy). But that is not necessary using  
the one-click ruby installer and VC6, building C/C++ extensions under  
windows from an already compiling library is really quite painless.

To qualify I am a long time C/C++ developer under Windows and Linux.  
But I have not encountered any Window's issues with regard to  
extension building -- I have been very pleased with how easy it is to  
use mkmf under Windows (I plan on trying out the new rake based tool  
soon :-).

Again if you are fighting with a unixy library or your library is  
inherently multi-threaded (like the Win32 service interface), then you  
will have some issues -- otherwise I find writing C extensions quite  
easy in both environments. Of course your mileage may vary.

pth

> **···**
>
> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > Patrick Hurley wrote:  
> > \> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:  
> > \> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> > \> \> x. It is significantly harder to extend ruby on windows than on one of  
> > \> \> the unixy systems.  
> > \>  
> > \> Not really. It is significantly harder to build libraries designed for  
> > \> unixy systems under windows than on those unixy systems. But the Ruby  
> > \> interface to C/C++ is pretty much identical between platforms. Why do  
> > \> you say it is harder?
> > 
> > Because ruby is unix focussed. All the core ruby developers are unix  
> > people. The ruby toolchain is a unix-oriented toolchain (see the  
> > recent 100+ message thread about ruby on windows).
> > 
> > To build on windows, one must either build ruby from scratch using  
> > mingw (a topic of some contention and basically a unix toolset for  
> > windows) or have vc6, which is less than readily available if you don't  
> > already have it. Ruby does not build easily in currently available  
> > microsoft tools.
> > 
> > Starting from scratch, on a vanilla unix system, anyone with reasonable  
> > unix and c knowledge can build ruby and a (minimal) custom extension in  
> > well under an hour.
> > 
> > Starting from scratch, on a vanilla windows system, I would be amazed  
> > if a windows guru could build ruby and a custom extension in under a  
> > full working day.
> > 
> > \>  
> > \> pth

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [23 August 2006 20:25 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/16 "2006-08-23T20:25:55Z")

</div>

For us works compiling with VC7 (2003) and even with VC8 (2005),  
although I have to copy those manifests andd runtime dlls along with  
extention dll. I know it isn't safe, however we do it for more than a  
year and without crashes. So it's possible, but YMMV.  
I wouldn't recommend it for production use without consulting with  
those who know what are the problematic cases.

To compile under VC8 I had to comment out the compiler check in  
config.h since one-click 1.8.4-20.

J.

> **···**
>
> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > ryan.raaum@gmail.com wrote:  
> > \> Patrick Hurley wrote:  
> > \> \> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:  
> > \> \> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> > \> \> \> x. It is significantly harder to extend ruby on windows than on one of  
> > \> \> \> the unixy systems.  
> > \> \>  
> > \> \> Not really. It is significantly harder to build libraries designed for  
> > \> \> unixy systems under windows than on those unixy systems. But the Ruby  
> > \> \> interface to C/C++ is pretty much identical between platforms. Why do  
> > \> \> you say it is harder?  
> > \>  
> > \> Because ruby is unix focussed. All the core ruby developers are unix  
> > \> people. The ruby toolchain is a unix-oriented toolchain (see the  
> > \> recent 100+ message thread about ruby on windows).  
> > \>  
> > \> To build on windows, one must either build ruby from scratch using  
> > \> mingw (a topic of some contention and basically a unix toolset for  
> > \> windows) or have vc6, which is less than readily available if you don't  
> > \> already have it. Ruby does not build easily in currently available  
> > \> microsoft tools.  
> > \>  
> > \> Starting from scratch, on a vanilla unix system, anyone with reasonable  
> > \> unix and c knowledge can build ruby and a (minimal) custom extension in  
> > \> well under an hour.  
> > \>  
> > \> Starting from scratch, on a vanilla windows system, I would be amazed  
> > \> if a windows guru could build ruby and a custom extension in under a  
> > \> full working day.
> > 
> > Qualifying my own post. Using mingw - slightly longer than on unix  
> > allowing for the time needed to install mingw. Using microsoft tools -  
> > much more difficult.

---

<div class="post-metadata">

**Author:** ![ryan.raaum](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@ryan.raaum](https://rubytalk.org/u/ryan.raaum)\
**Post date:** [24 August 2006 01:20 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/17 "2006-08-24T01:20:12Z")

</div>

Patrick Hurley wrote:

> \>  
> \> Patrick Hurley wrote:  
> \> \> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> \> \> \> x. It is significantly harder to extend ruby on windows than on one of  
> \> \> \> the unixy systems.  
> \> \>  
> \> \> Not really. It is significantly harder to build libraries designed for  
> \> \> unixy systems under windows than on those unixy systems. But the Ruby  
> \> \> interface to C/C++ is pretty much identical between platforms. Why do  
> \> \> you say it is harder?  
> \>  
> \> Because ruby is unix focussed. All the core ruby developers are unix  
> \> people. The ruby toolchain is a unix-oriented toolchain (see the  
> \> recent 100+ message thread about ruby on windows).  
> \>  
> \> To build on windows, one must either build ruby from scratch using  
> \> mingw (a topic of some contention and basically a unix toolset for  
> \> windows) or have vc6, which is less than readily available if you don't  
> \> already have it. Ruby does not build easily in currently available  
> \> microsoft tools.  
> \>  
> \> Starting from scratch, on a vanilla unix system, anyone with reasonable  
> \> unix and c knowledge can build ruby and a (minimal) custom extension in  
> \> well under an hour.  
> \>  
> \> Starting from scratch, on a vanilla windows system, I would be amazed  
> \> if a windows guru could build ruby and a custom extension in under a  
> \> full working day.  
> \>  
> \> \>  
> \> \> pth  
> \>
> 
> I won't argue that building Ruby on Windows is somewhat difficult  
> (well gathering the unixy tool chain for Windows takes some patience  
> and then the build is pretty easy). But that is not necessary using  
> the one-click ruby installer and VC6, building C/C++ extensions under  
> windows from an already compiling library is really quite painless.

The key here is that you have a tool (VC6) which is not generally  
available. If one doesn't have this tool, as I don't, then extending  
ruby on windows becomes much more challenging.

> **···**
>
> > On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:  
> > \> \> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > To qualify I am a long time C/C++ developer under Windows and Linux.  
> > But I have not encountered any Window's issues with regard to  
> > extension building -- I have been very pleased with how easy it is to  
> > use mkmf under Windows (I plan on trying out the new rake based tool  
> > soon :-).
> > 
> > Again if you are fighting with a unixy library or your library is  
> > inherently multi-threaded (like the Win32 service interface), then you  
> > will have some issues -- otherwise I find writing C extensions quite  
> > easy in both environments. Of course your mileage may vary.
> > 
> > pth

---

<div class="post-metadata">

**Author:** ![Leslie\_Viljoen1](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Leslie\_Viljoen1](https://rubytalk.org/u/Leslie_Viljoen1)\
**Post date:** [23 August 2006 21:14 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/18 "2006-08-23T21:14:09Z")

</div>

In passing: VC6 is quite old now, can Microsoft not be persuaded to  
give it away free? I'd be happy to put my CD up for download if it  
were legal.

Les

> **···**
>
> On 8/23/06, Jan Svitok \<jan.svitok@gmail.com\> wrote:
> 
> > On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:  
> > \>  
> > \> ryan.raaum@gmail.com wrote:  
> > \> \> Patrick Hurley wrote:  
> > \> \> \> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:  
> > \> \> \> \> Also, it is important to ask if you are on windows or linux/bsd/mac os  
> > \> \> \> \> x. It is significantly harder to extend ruby on windows than on one of  
> > \> \> \> \> the unixy systems.  
> > \> \> \>  
> > \> \> \> Not really. It is significantly harder to build libraries designed for  
> > \> \> \> unixy systems under windows than on those unixy systems. But the Ruby  
> > \> \> \> interface to C/C++ is pretty much identical between platforms. Why do  
> > \> \> \> you say it is harder?  
> > \> \>  
> > \> \> Because ruby is unix focussed. All the core ruby developers are unix  
> > \> \> people. The ruby toolchain is a unix-oriented toolchain (see the  
> > \> \> recent 100+ message thread about ruby on windows).  
> > \> \>  
> > \> \> To build on windows, one must either build ruby from scratch using  
> > \> \> mingw (a topic of some contention and basically a unix toolset for  
> > \> \> windows) or have vc6, which is less than readily available if you don't  
> > \> \> already have it. Ruby does not build easily in currently available  
> > \> \> microsoft tools.  
> > \> \>  
> > \> \> Starting from scratch, on a vanilla unix system, anyone with reasonable  
> > \> \> unix and c knowledge can build ruby and a (minimal) custom extension in  
> > \> \> well under an hour.  
> > \> \>  
> > \> \> Starting from scratch, on a vanilla windows system, I would be amazed  
> > \> \> if a windows guru could build ruby and a custom extension in under a  
> > \> \> full working day.  
> > \>  
> > \> Qualifying my own post. Using mingw - slightly longer than on unix  
> > \> allowing for the time needed to install mingw. Using microsoft tools -  
> > \> much more difficult.
> > 
> > For us works compiling with VC7 (2003) and even with VC8 (2005),  
> > although I have to copy those manifests andd runtime dlls along with  
> > extention dll. I know it isn't safe, however we do it for more than a  
> > year and without crashes. So it's possible, but YMMV.  
> > I wouldn't recommend it for production use without consulting with  
> > those who know what are the problematic cases.
> > 
> > To compile under VC8 I had to comment out the compiler check in  
> > config.h since one-click 1.8.4-20.

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [24 August 2006 02:17 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/19 "2006-08-24T02:17:58Z")

</div>

What also is helpful is if more and more people write  
small Tutorials, in total I found only about ~3 really  
useful resources about this (aside from the README)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Patrick\_Hurley1](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Patrick\_Hurley1](https://rubytalk.org/u/Patrick_Hurley1)\
**Post date:** [24 August 2006 03:36 UTC](https://rubytalk.org/t/ruby-c-c-interface/30249/20 "2006-08-24T03:36:44Z")

</div>

Sorry for being thick headed -- I can see where this would be a  
problem. I have many different Win32 C/C++ compilers dating back to a  
pile of 5.25" floppies from Zortech, so I never considered this. Just  
to check I shot over to ebay -- VC 6 goes for more than Studio 2005 (I  
was thinking you would be able to pick it up for next to nothing).

pth

> **···**
>
> On 8/23/06, ryan.raaum@gmail.com \<ryan.raaum@gmail.com\> wrote:
> 
> > The key here is that you have a tool (VC6) which is not generally  
> > available. If one doesn't have this tool, as I don't, then extending  
> > ruby on windows becomes much more challenging.

[Next page](https://rubytalk.org/t/ruby-c-c-interface/30249.md?page=2)
