# Ruby lnline question

**URL:** <https://www.ruby-forum.com/t/ruby-lnline-question/121183>\
**Category:** Ruby\
**Created:** [November 25, 2007, 12:09am UTC](https://www.ruby-forum.com/t/ruby-lnline-question/121183 "2007-11-25T00:09:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 25, 2007, 12:09am UTC](https://www.ruby-forum.com/t/ruby-lnline-question/121183/1 "2007-11-25T00:09:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 25, 2007, 3:43am UTC](https://www.ruby-forum.com/t/ruby-lnline-question/121183/2 "2007-11-25T03:43:51Z")

</div>

Quoth Axel E.:

> ```
> printf("%d\n",argc);
> 
> ```
> 
> #!/usr/local/bin/ruby -w  
> for (x=0; x\<argc; x++)  
> ERRORS!
> 
> What am I missing ?
> 
> Thank you very much.
> 
> Best regards,
> 
> Axel

This isn’t how RubyInline is supposed to be used. RubyInline is mostly  
for  
functions with a defined number of arguments AFAIK. It will infer the  
correct  
ruby type \<-\> C type conversion automatically for you for that, but I  
don’t  
think it does varargs.

Furthermore, if you were writing a C ruby extension with a varargs  
function,  
the signature is:

VALUE func(int argc, VALUE \*argv, VALUE obj)

(Where argc is the actual number of arguments, argv is the C array of  
the  
arguments, and obj is the receiver (quoting README.EXT from Ruby  
source).)

HTH,
