Compiling a Ruby extension

A

Axel

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

Axel

Hello, Steve!

Thanks for answering so quickly!
You can't use mingw to compile your extensions. You need to use the MS
compiler.

What a pity! I guess this is due to the fact that Microsoft uses a
different executable format than MinGW and the One-Click Installer
happens to be compiled with Microsoft's compiler. I seem to remember
having seen a tool that converts object files between these formats.
Maybe I'll try that one before cobbling together a Microsoft
installation.

-------------- Axel <><
 
C

Curt Hibbs

------=_Part_13212_28967513.1125580128843
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=20
Hello, Steve!
=20
Thanks for answering so quickly!
=20
=20
What a pity! I guess this is due to the fact that Microsoft uses a
different executable format than MinGW and the One-Click Installer
happens to be compiled with Microsoft's compiler. I seem to remember
having seen a tool that converts object files between these formats.
Maybe I'll try that one before cobbling together a Microsoft
installation.


Here are the instructions for installing and using the free version of the=
=20
microsoft compiler:

Installing the free compiler from Microsoft

1. Download and install the SDK from
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

2. Install the .NET redistributable package from http://tinyurl.com/95zt
3. Install the .NET SDK from http://tinyurl.com/97x7
4. Install the VC Toolkit from
http://msdn.microsoft.com/visualc/vctoolkit2003/

5. Copy the directories under 'C:\Program Files\Microsoft Visual C++=20
Toolkit 2003' to 'C:\Program Files\Microsoft Visual Studio .NET 2003\VC7',=
=20
overwriting all the files there. This is recommended because the VC Toolkit=
=20
does code optimization, while the .NET SDK does not.
6. Set your environment variables. Run 'C:\Program=20
Files\Microsoft.NET\SDK\V1.1\bin\sdkvars.bat'. Then run 'C:\Program=20
Files\Microsoft SDK\setenv.bat'. You can do this permanently through window=
s=20
or on a per session basis.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
expanded tiny-urls:

2. http://tinyurl.com/95zt =3D
http://www.microsoft.com/downloads/details.aspx?familyid=3D262d25e3-f589-48=
42-8157-034d1e7cf3a3&displaylang=3Den


3. http://tinyurl.com/97x7
http://www.microsoft.com/downloads/details.aspx?FamilyId=3D9B3A2CA6-3647-40=
70-9F41-A333C6B9181D&displaylang=3Den


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

------=_Part_13212_28967513.1125580128843--
 

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,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top