Forum: Ruby C Extensions not working on Windows XP 64

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ad7b5505e4576a5466db6fa5e3eb8db5?d=identicon&s=25 Matt (Guest)
on 2006-02-23 22:22
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.
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-02-23 22:34
(Received via mailing list)
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
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-02-23 22:37
(Received via mailing list)
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
8d775a4f841200707929b36728efcccf?d=identicon&s=25 Suraj Kurapati (Guest)
on 2006-02-27 06:02
(Received via mailing list)
-----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-----
This topic is locked and can not be replied to.