C Extensions not working on Windows XP 64

M

Matt

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

Daniel Harple

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

Suraj Kurapati

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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-----
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top