Compiling a Ruby extension
- From: "Axel" <anieden@xxxxxx>
- Date: 31 Aug 2005 05:01:17 -0700
Hello!
I am trying to manually compile a tiny Ruby extension, but finally run
into a problem. I wonder if anyone can give me a hint on what's wrong?
The code for the extension:
#include <stdio.h>
#include "ruby.h"
__declspec(dllexport) void Init_MyExt();
static VALUE initialize(VALUE self);
static VALUE perform(VALUE self);
VALUE cMyExt;
void Init_MyExt() {
cMyExt = rb_define_class("MyExt", rb_cObject);
rb_define_method(cMyExt, "initialize", initialize, 0);
rb_define_method(cMyExt, "perform", perform, 0);
}
static VALUE initialize(VALUE self) {
return self;
}
static VALUE perform(VALUE self) {
puts("Here is the C code!");
return self;
}
My setup: Windows XP, Ruby One-Click Installer 1.8.2-15, MinGW 3.4.2.
Now I compile the code above into a DLL:
gcc -c -IC:\ruby\lib\ruby\1.8\i386-mswin32 myext.c
gcc -shared -o MyExt.dll -Wl,-s myext.o C:\ruby\lib\msvcrt-ruby18.lib
Now I try to call this DLL via the following client:
require 'MyExt'
e = MyExt.new
e.perform
Unfortunatly, this results in the following error message:
../MyExt.dll: wrong argument type Fixnum (expected Class) (TypeError)
from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
from C:/temp/rubyext/test.rb:1
Any ideas?
.
- Follow-Ups:
- Re: Compiling a Ruby extension
- From: Steve
- Re: Compiling a Ruby extension
- Prev by Date: Re: A (newbie-ish) question about project organization
- Next by Date: Ruby documentation typo
- Previous by thread: Re: Win32ole object collection mapping to array ?
- Next by thread: Re: Compiling a Ruby extension
- Index(es):