# C Extensions not working on Windows XP 64

**URL:** <https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527>\
**Category:** Ruby\
**Created:** [February 23, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527 "2006-02-23T22:22:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 23, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527/1 "2006-02-23T22:22:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 23, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527/2 "2006-02-23T22:34:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 23, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527/3 "2006-02-23T22:37:30Z")

</div>

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

> Classes must be constant

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

– Daniel

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 27, 2006, 6:02am UTC](https://www.ruby-forum.com/t/c-extensions-not-working-on-windows-xp-64/72527/4 "2006-02-27T06:02:14Z")

</div>

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