[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby C/C++ Interface

kandlinger

8/23/2006 7:50:00 AM

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 ?

19 Answers

Dido Sevilla

8/23/2006 8:04:00 AM

0

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.

kandlinger

8/23/2006 8:22:00 AM

0

> 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 ?

Dido Sevilla

8/23/2006 9:06:00 AM

0

On 8/23/06, kandlinger@gmx.de <kandlinger@gmx.de> wrote:
> 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).

Leslie Viljoen

8/23/2006 9:40:00 AM

0

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-t...

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

Jano Svitok

8/23/2006 9:43:00 AM

0

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

http://www...

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.

ryan.raaum@gmail.com

8/23/2006 12:30:00 PM

0

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.

Robin Stocker

8/23/2006 1:32:00 PM

0

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...

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/i...

M. Edward (Ed) Borasky

8/23/2006 1:44:00 PM

0

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...
>
> 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.
>
>
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://ww....

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.


Patrick Hurley

8/23/2006 2:42:00 PM

0

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?

pth

ryan.raaum@gmail.com

8/23/2006 7:02:00 PM

0


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