Subject: [ruby-ffi] Re: Help for Beginner - Compiling C Extension on Windows |
From: Karl |
Date: 9/2/10 4:44 PM |
To: ruby-ffi |
On Sep 2, 11:28 am, Luis Lavena <luislav...@gmail.com> wrote:
<threadh...@gmail.com> wrote:On Thu, Sep 2, 2010 at 1:22 PM, KarlBoring 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.http://wiki.github.com/ffi/ffi With examples to access Windows API.Hello Karl Ruby FFI aims to replace the need to compile an extension to access a library, please see the wiki:
Yes, and I plan on using it. But I still need to create some custom C code to process the 2M-10M data points generated by the DAQ board. I could do it in ruby, but the speed would be very poor as I need to de- bounce the analog input readings.
Going to respond your question anyhow, but please read the wiki.
And I did, many times. I even went to the point of doing everything on my ubuntu box and everything works exactly as expected. Just when I try it on WIN does is fail.
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)
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 /mingwAlso tried setup up 'fstab' using this siteYou 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.http://github.com/oneclick/rubyinstaller/wiki/Development-KitYou'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.
Honestly, I would have asked here unless I had read the wiki and tried this many, many times. Completely removed c:\ruby197 and c:\devkit, also remove all reference in system environment PATH. Installed ruby 1.8.7 with rubyinstaller.org. Installed devkit following the instruction on the wiki, to the letter. Ran .\devkitvars.bat Did a 'gem install thin --platform=ruby' just to make sure things compile... no errors. Back my source directory: ruby extconf.rb (no errors) Ran 'make' and I get the exact same error as above. BTW, I do have VS8 Express installed. Is that causing the issue? Also, I did a system search for ruby.exe and only one in c:\ruby187 is found. And I checked my rbconfig.rb (I can past the entire content if that helps), all the references I see are to i585-pc-mingw32, mingw32, gcc, but CONFIG["RUBY_SO_NAME"] = "msvcrt-ruby18" That's the only reference not to mingw32 I see. So, I'm still where I started.