Extending ruby with c

R

ruby talk

------=_Part_10613_18890234.1137804502240
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello,
I am looking for an example/tutorial on extending ruby with C using windows=
 
E

Eero Saynatkari

ruby said:
Hello,
I am looking for an example/tutorial on extending ruby with C using
windows.
I add the using windows because I was to extend pcap ruby to windows
(one
day), and it is what i currently have installed. I read the pickaxe book
and
the example does not work for me. I think my problem with pickaxe
example is
the location of my file in the ruby dir. I was getting and error with
the
value statment so i removed all the code excpet the return self in the
functions. and i get

c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__':
C:\ruby\lib\ruby\Test.rb:7: void value expression (SyntaxError)
return self;
^
C:\ruby\lib\ruby\Test.rb:7: odd number list for Hash
return self;
^
C:\ruby\lib\ruby\Test.rb:7: syntax error
return self;
^
C:\ruby\lib\ruby\Test.rb:8: syntax error from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
from testtest.rb:1

Is return self; in the C code? (The C level does not have an
implicit self.) Does everything compile OK with extconf.rb?

If you post the code, we can troubleshoot.
I read this
http://www.onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html and
it is
in linux, make does not work.

Thank you for your time.
Becker


E
 
R

ruby talk

------=_Part_11397_24049364.1137813098120
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I am using the pickaxe example to help learn how it is writen.
Thank you once again.
Becker

my run program
Code:
require "C:\\ruby\\Test"
t =3D Test.new()
t.add("Bill Chase")
[code]

my code example from pickaxe  saved as a .rb
[code]
#include "ruby.h"
static VALUE t_init(VALUE self)
{
VALUE arr;
arr =3D rb_ary_new();
rb_iv_set(self, "@arr", arr);
return self;
}

static VALUE t_add(VALUE self, VALUE anObject)
{
VALUE arr;
arr =3D rb_iv_get(self, "@arr");
rb_ary_push(arr, anObject);
return arr;
}

VALUE cTest;

void Init_Test() {
cTest =3D rb_define_class("Test", rb_cObject);
rb_define_method(cTest, "initialize", t_init, 0);
rb_define_method(cTest, "add", t_add, 1);
}

[code]


error
[error]
C:\ruby\Test.rb:2: warning: parenthesize argument(s) for future version
C:\ruby\Test.rb:2: warning: parenthesize argument(s) for future version
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__'=
:
C:\ruby\Test.rb:4: syntax error (SyntaxError)
VALUE arr;
^
C:\ruby\Test.rb:8: syntax error    from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
from testtest.rb:1
[error]




[QUOTE]
Is return self; in the C code? (The C level does not have an
implicit self.) Does everything compile OK with extconf.rb?

If you post the code, we can troubleshoot.



E
[/QUOTE]

------=_Part_11397_24049364.1137813098120--
 
E

Eero Saynatkari

ruby said:
I am using the pickaxe example to help learn how it is writen.
Thank you once again.
Becker

my run program
Code:
require "C:\\ruby\\Test"
t = Test.new()
t.add("Bill Chase")
[code]

my code example from pickaxe  saved as a .rb[/QUOTE]

This here is the problem; the below code must be
saved as a .c file and then compiled to a library
using extconf.rb (the Pickaxe should have further
instructions for this). Once done, you will have
a Test.so file that you can #require for example
from irb.
[QUOTE]
[code]
#include "ruby.h"
static VALUE t_init(VALUE self)
{
VALUE arr;
arr = rb_ary_new();
rb_iv_set(self, "@arr", arr);
return self;
}

static VALUE t_add(VALUE self, VALUE anObject)
{
VALUE arr;
arr = rb_iv_get(self, "@arr");
rb_ary_push(arr, anObject);
return arr;
}

VALUE cTest;

void Init_Test() {
cTest = rb_define_class("Test", rb_cObject);
rb_define_method(cTest, "initialize", t_init, 0);
rb_define_method(cTest, "add", t_add, 1);
}

[code]


< Error messages elided />[/QUOTE]

The code itself is fine, you just need to compile it.


E
 
R

ruby talk

------=_Part_11469_23289621.1137816257155
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a command.
What do i do with the file instead?
Becker


[QUOTE]
[QUOTE="ruby"]
I am using the pickaxe example to help learn how it is writen.
Thank you once again.
Becker

my run program
[code]
require "C:\\ruby\\Test"
t =3D Test.new()
t.add("Bill Chase")
[code]

my code example from pickaxe  saved as a .rb[/QUOTE]

This here is the problem; the below code must be
saved as a .c file and then compiled to a library
using extconf.rb (the Pickaxe should have further
instructions for this). Once done, you will have
a Test.so file that you can #require for example
from irb.
[QUOTE]
[code]
#include "ruby.h"
static VALUE t_init(VALUE self)
{
VALUE arr;
arr =3D rb_ary_new();
rb_iv_set(self, "@arr", arr);
return self;
}

static VALUE t_add(VALUE self, VALUE anObject)
{
VALUE arr;
arr =3D rb_iv_get(self, "@arr");
rb_ary_push(arr, anObject);
return arr;
}

VALUE cTest;

void Init_Test() {
cTest =3D rb_define_class("Test", rb_cObject);
rb_define_method(cTest, "initialize", t_init, 0);
rb_define_method(cTest, "add", t_add, 1);
}

[code]


< Error messages elided />[/QUOTE]

The code itself is fine, you just need to compile it.


E
[/QUOTE]

------=_Part_11469_23289621.1137816257155--
 
E

Eero Saynatkari

ruby said:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a command.
What do i do with the file instead?[/QUOTE]

Windows can use a program called 'nmake' that you can use.
In addition to this, you would need to install a C compiler.
Microsoft does offer a free version of theirs. Both should
be available somewhere on http://www.msdn.com.

Alternatively, you could install the MinGW toolkit from
http://www.mingw.org, it provides minimal GNU tools.
[QUOTE]
Becker[/QUOTE]


E
 
R

ruby talk

------=_Part_11517_13972941.1137818189818
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Thank you i found nmake at
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q132084

using nmake i get this error
C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x1=
'
Stop.

C:\ruby\code>

I will try the other program next.
Becker

ruby said:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a command=[/QUOTE][/QUOTE]
 
R

ruby talk

------=_Part_11845_27190644.1137821624698
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

For the other program i get this error. I will never win at this. I am
currently downloading the 2005 express c++ it should have the cl.exe file?


iv@SLAB-1298E5B638 /c/ruby/code
$ make
Makefile:105: *** target pattern contains no `%'. Stop.


Becker

Thank you i found nmake at
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q132084

using nmake i get this error
C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code
'0x1'
Stop.

C:\ruby\code>

I will try the other program next.
Becker

ruby said:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a command.
What do i do with the file instead?[/QUOTE]

Windows can use a program called 'nmake' that you can use.
In addition to this, you would need to install a C compiler.
Microsoft does offer a free version of theirs. Both should
be available somewhere on http://www.msdn.com.

Alternatively, you could install the MinGW toolkit from
http://www.mingw.org , it provides minimal GNU tools.
[QUOTE]
Becker[/QUOTE]


E
[/QUOTE]

------=_Part_11845_27190644.1137821624698--
 
R

ruby talk

------=_Part_15657_18557433.1137868680435
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Good I got CL to work! i donlowaded Visual C++ Toolkit 2003 for free and now cl
works.

Bad now i get a differnt error.

C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
Test.c
c:\ruby\lib\ruby\1.8\i386-mswin32\win32\win32.h(25) : fatal error C1083:
Cannot
open include file: 'windows.h': No such file or directory
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x2=
'
Stop.

C:\ruby\code>

Becker

For the other program i get this error. I will never win at this. I am
currently downloading the 2005 express c++ it should have the cl.exe file= ?


iv@SLAB-1298E5B638 /c/ruby/code
$ make
Makefile:105: *** target pattern contains no `%'. Stop.


Becker

Thank you i found nmake at
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q132084

using nmake i get this error
C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code
'0x1'
Stop.

C:\ruby\code>

I will try the other program next.
Becker

ruby talk wrote:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a command.
What do i do with the file instead?

Windows can use a program called 'nmake' that you can use.
In addition to this, you would need to install a C compiler.
Microsoft does offer a free version of theirs. Both should
be available somewhere on http://www.msdn.com.

Alternatively, you could install the MinGW toolkit from
http://www.mingw.org , it provides minimal GNU tools.

Becker


E
[/QUOTE]
[/QUOTE]

------=_Part_15657_18557433.1137868680435--
 
J

Joe Van Dyk

Good I got CL to work! i donlowaded Visual C++ Toolkit 2003 for free and now = cl
works.

Bad now i get a differnt error.

C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
Test.c
c:\ruby\lib\ruby\1.8\i386-mswin32\win32\win32.h(25) : fatal error C1083:
Cannot
open include file: 'windows.h': No such file or directory

You need to tell the compiler about the directory that includes the
header file windows.h. You can probably do this via giving the
where <dir> is the directory said:
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0= x2'
Stop.

C:\ruby\code>

Becker



For the other program i get this error. I will never win at this. I am
currently downloading the 2005 express c++ it should have the cl.exe fi= le?


iv@SLAB-1298E5B638 /c/ruby/code
$ make
Makefile:105: *** target pattern contains no `%'. Stop.


Becker

Thank you i found nmake at
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q132084

using nmake i get this error
C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return cod= e
'0x1'
Stop.

C:\ruby\code>

I will try the other program next.
Becker


ruby talk wrote:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a
command.
What do i do with the file instead?

Windows can use a program called 'nmake' that you can use.
In addition to this, you would need to install a C compiler.
Microsoft does offer a free version of theirs. Both should
be available somewhere on http://www.msdn.com.

Alternatively, you could install the MinGW toolkit from
http://www.mingw.org , it provides minimal GNU tools.

Becker


E
[/QUOTE]
[/QUOTE]
[/QUOTE]
 
A

Anatol Pomozov

------=_Part_5889_20126131.1137871549144
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

See file
"C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\vsvars32.bat"

that .bat file registres all EVN variables needed for ms compiler. You need
to add those PATH, INCLUDE, LIB add to user env variables.
 
R

ruby talk

------=_Part_15937_25439019.1137872515287
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I changed the cl.exe option to -I c:\Dev-cpp\include /I also works, but th=
e
windef.h file is in the same Dir as the windows.h


C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -I c:\C:\Dev-Cpp\include -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/l
ib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code
-I.
-I./.. -I./../missing -c -TcTest.c
Test.c
c:/ruby\lib\ruby\1.8\i386-mswin32\windows.h(48) : fatal error C1083: Cannot
open
include file: 'windef.h': No such file or directory
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x2=
'
Stop.

C:\ruby\code>



Good I got CL to work! i donlowaded Visual C++ Toolkit 2003 for free and no=
w
cl
works.

Bad now i get a differnt error.

C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
Test.c
c:\ruby\lib\ruby\1.8\i386-mswin32\win32\win32.h(25) : fatal error C1083= :
Cannot
open include file: 'windows.h': No such file or directory

You need to tell the compiler about the directory that includes the
header file windows.h. You can probably do this via giving the
where <dir> is the directory said:
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x2'
Stop.

C:\ruby\code>

Becker



For the other program i get this error. I will never win at this. I a= m
currently downloading the 2005 express c++ it should have the cl.exef= ile?


iv@SLAB-1298E5B638 /c/ruby/code
$ make
Makefile:105: *** target pattern contains no `%'. Stop.


Becker


Thank you i found nmake at
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q132084

using nmake i get this error
C:\ruby\code>nmake

Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

cl -nologo -MD -Zi -O2b2xg- -G6 -I.
-Ic:/ruby/lib/ruby/1.8/i386-mswin32
-Ic:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/ruby/code -I. -I./..
-I./../missing -c
-TcTest.c
'cl' is not recognized as an internal or external command,
operable program or batch file.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code
'0x1'
Stop.

C:\ruby\code>

I will try the other program next.
Becker


ruby talk wrote:
Hello,
i created the .rb
Code:
require 'mkmf'

dir_config("Test")

create_makefile("Test")
[code]

but it only created the makefile which in windows make is not a
command.
What do i do with the file instead?

Windows can use a program called 'nmake' that you can use.
In addition to this, you would need to install a C compiler.
Microsoft does offer a free version of theirs. Both should
be available somewhere on http://www.msdn.com.

Alternatively, you could install the MinGW toolkit from
http://www.mingw.org , it provides minimal GNU tools.

Becker


E
[/QUOTE]
[/QUOTE]
[/QUOTE]

------=_Part_15937_25439019.1137872515287--
 
R

ruby talk

------=_Part_15997_17231897.1137873581464
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Did that, I got an error for the dir having a space in the ie : f:\document=
s
and settings, so i copied the code folder to my c drive root ( c:\rcode)
and now i get the error

cl -nologo -LD -FeTest.so TcTest.obj Test.obj msvcrt-ruby18.lib
oldname
s.lib user32.lib advapi32.lib wsock32.lib -link -incremental:no -debug
-opt:ref
-opt:icf -dll -libpath:"c:/ruby/lib" -def:Test-i386-mswin32.def
cl : Command line warning D4024 : unrecognized source file type '.', object
file
assumed
LINK : fatal error LNK1104: cannot open file '.'
NMAKE : fatal error U1077: 'F:\WINDOWS\system32\cmd.exe' : return code '0x2=
'
Stop.


Becker

See file
"C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\vsvars32.bat"

that .bat file registres all EVN variables needed for ms compiler. You
need
to add those PATH, INCLUDE, LIB add to user env variables.

------=_Part_15997_17231897.1137873581464--
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top