Ruby lnline question

A

Axel Etzold

Dear all,

I'd like to have Ruby Inline create a Ruby method from the
following C code:

#include <stdio.h>

int main(int argc, char *argv[])
{
int x;
printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

(so that I can enter a variable number of arguments and have these
returned.)

Now I tried:

#!/usr/local/bin/ruby -w

require 'rubygems'
require 'inline'

class Example
inline:)C) do |builder|
builder.c 'int main(int argc,char *argv[])
{
int x;
printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}'
end
end

p Example.new.main(3,'a','b','c')

but got:

WARNING: 'char * argv[]' not understood
i.rb: In function ‘main’:
i.rb:15: error: ‘argv’ undeclared (first use in this function)
i.rb:15: error: (Each undeclared identifier is reported only once
i.rb:15: error: for each function it appears in.)
i.rb:9: warning: return type of ‘main’ is not ‘int’
/usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:402:in `build': error executing gcc -shared -fPIC -g -O2 -I /usr/local/lib/ruby/1.8/x86_64-linux -I /usr/local/include -o "/home/axel/.ruby_inline/Inline_Example_fad5.so" "/home/axel/.ruby_inline/Inline_Example_fad5.c" : 256 (CompilationError)
Renamed /home/axel/.ruby_inline/Inline_Example_fad5.c to /home/axel/.ruby_inline/Inline_Example_fad5.c.bad from /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:679:in `inline'
from i.rb:7

What am I missing ?

Thank you very much.

Best regards,

Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top