Subject:
Re: [ruby-ffi] Help for Beginner - Compiling C Extension on Windows
From:
Luis Lavena
Date:
9/2/10 1:28 PM
To:
ruby-ffi@googlegroups.com

On Thu, Sep 2, 2010 at 1:22 PM, Karl <threadhead@gmail.com> wrote:
> Boring Background:
> Let me say first that I'm no Windows expert and it's been 20 years
> since I last compiled anything I wrote in C. But I need to access an
> API on a Windows machine (controls a DAQ board) from Ruby. So I'm
> trying to get the first steps down, compiling a C lib I can access
> through ruby.
>
> Also, I apologize if this is the wrong place to post, but it seems
> that this is the only forum that C extension writers on windows
> frequent.
>
>

Hello Karl

Ruby FFI aims to replace the need to compile an extension to access a
library, please see the wiki:

http://wiki.github.com/ffi/ffi

With examples to access Windows API.

Going to respond your question anyhow, but please read the wiki.

> Can't Compile Simple C DLL:
> Installed Ruby 1.8.7-p302 from rubyinstaller.org (used the .exe).
> Installed DevKit-4.5.0-20100819-1536-sfx.exe from rubyinstaller.org
> Performed the devkit install, all it working (installing gems that
> require compiling work)
>
> Also tried setup up 'fstab' using this site
> http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/ but
> nothing he shows looks remotely like my installation. So I set C:
> \devkit\etc\fstab to:
>  C:/devkit/mingw/lib/gcc/mingw32/4.5.0  /mingw
>

You don't need to modify the fstab.

>
> Trying to compile the following:
> #stree.c
> #include <ruby.h>
>
> static VALUE hello_world(VALUE klass)
> {
>  return rb_str_new2("hello world");
> }
>
> void Init_stree()
> {
>  VALUE mStree = rb_define_module("Stree");
>  rb_define_singleton_method(mStree, "hello_world", hello_world, 0);
> }
>
>
> #extconf.rb
> require 'mkmf'
> create_makefile('stree/stree')
>
>
> On the win machine I run: ruby extconf.rb
>  creates the Makefile, no errors
>
> I run: 'make' and receive the following:
>  Compile the C Code to a DLL
>  'cl' is not recognized as an internal or external command, operable
> program or batch file.
>  Could Not Find C:\rails\ext_test\stree\ext\stree\*.obj
>  Done.
>

You're using the wrong ruby to compile. Basically you're running Ruby
compiled with mswin32 (Visual C) instead of RubyInstaller.

It trying to look for cl indicates that rbconfig used by your ruby
installation came from mswin32 version.

So, either you installed RubyInstaller on top of another Ruby, or you
modified anything in your installation.

Please try a clean Ruby+DevKit installation.

Also, please read the instructions at our wiki for details on DevKit
installation.

http://github.com/oneclick/rubyinstaller/wiki/Development-Kit
-- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry