[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

C Extensions not working on Windows XP 64

Matt

2/23/2006 9:23:00 PM

I can not for the life of me get even the simplest C extension example
to load into ruby on Windows XP. The first case I tried actually was
the example provided by SWIG (the simple example). It fails with the
message
runme.rb:3:in `require': 127: The specified procedure could not be
found. - In
it_Example (LoadError)
/Example.dll
from runme.rb:3

The example was compiled with the provided MS-VC++ 6 project without
error. A dumpbin of example.dll reveals that the symbol Init_Example is
in fact exported. The same error is reported in both ruby 1.6.8 and
ruby 1.8.2. This is supposed to work in theory since it's
'automatically' generated by SWIG


I then tried to generate my own example based on some tutorials.
//--------------------simple.c------------------------------------------------
#include "ruby.h"

static VALUE simple_initialize(VALUE self, int iValue)
{
rb_iv_set(self,"@i",iValue);
rb_iv_set(self,"@a",rb_ary_new());
return self;

}

static VALUE simple_get_i(VALUE self)
{
return rb_iv_get(self,"@i");

}

static VALUE simple_set_i(VALUE self, int iValue)
{
return rb_iv_set(self,"@i",iValue);

}

static VALUE simple_get_a(VALUE self)
{
return rb_iv_get(self,"@a");

}

VALUE csimple;

void Init_simple()
{

csimple = rb_define_class("simple",rb_cObject);
rb_define_method(csimple,"initialize",simple_initialize,1);

rb_define_method(csimple,"i", simple_get_i, 0);
rb_define_method(csimple,"i=", simple_set_i, 1);
rb_define_method(csimple,"a", simple_get_a, 0);

}

//---------------------------------------------------------------------


#----- simple.rb ------------
require "simple"

s = simple.new(123)

p s.i
p s.a

s.i = 456
s.a.push("Hello")
s.a.push("World")

p s.a
#-----------------------------

The compile procedure from MS-VC++ 6
cl /LD /I$(RUBY_INCLUDE) /O2 simple.c $(RUBY_LIBPATH)\$(RUBY_LIB) /link
/def:simple.def

which compiles without error or warning. dumpbin reveals that
Dump of file simple.dll

File Type: DLL

Section contains the following exports for simple.dll

0 characteristics
43FE269D time date stamp Thu Feb 23 16:18:21 2006
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 Init_simple

Summary

4000 .data
1000 .rdata
1000 .reloc
5000 .text


However running
D:\ruby>ruby simple.rb
/simple.rb:4: undefined local variable or method `simple' for
#<Object:0x5b6961
8> (NameError)
from simple.rb:2:in `require'
from simple.rb:2

This is the result from running ruby 1.6.8
I might go back and try 1.8.2 again later, but for now I'll use python.
At least SWIG seems to work with it on windows.

--
Posted via http://www.ruby-....


3 Answers

Daniel Harple

2/23/2006 9:32:00 PM

0


On Feb 23, 2006, at 10:22 PM, Matt wrote:

> ./simple.rb:4: undefined local variable or method `simple' for
> #<Object:0x5b6961
> 8> (NameError)
> from simple.rb:2:in `require'
> from simple.rb:2

Classes must be constant. Try naming your class ``Simple''.
^

-- Daniel


Daniel Harple

2/23/2006 9:37:00 PM

0


On Feb 23, 2006, at 10:31 PM, Daniel Harple wrote:

> Classes must be constant

That should be ``Class names''. Sorry for the spam.

-- Daniel


Suraj Kurapati

2/27/2006 5:00:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matt wrote:
> I then tried to generate my own example based on some tutorials.

Ack! I see some integers being directly stored into a Ruby VALUE.
Remember to cast them properly using INT2NUM() or, if you're feeling
dangerous, INT2FIX().

> static VALUE simple_initialize(VALUE self, int iValue)
> {
> rb_iv_set(self,"@i",iValue);

rb_iv_set(self,"@i",INT2NUM(iValue));


> static VALUE simple_set_i(VALUE self, int iValue)
> {
> return rb_iv_set(self,"@i",iValue);

return rb_iv_set(self,"@i",INT2NUM(iValue));
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFEAoaZmV9O7RYnKMcRAqwGAJ9uJueRap0sIm9OXXZBIzsiyNgiXwCfbK8q
V9XrCvKOfONVlVEYJxI1Lk0=
=RuMj
-----END PGP SIGNATURE-----