From: Bob Calco Date: 2002-05-27T01:34:38+09:00 Subject: RE: compilation ignorance repeater: On windows you can compile Ruby out-of-the-box one of two ways: Using the MS Visual C++ compiler, or using the Cygwin gcc compiler. If you are using the cygwin distro of Ruby, any extensions that you want to build statically into the distro should be compiled with the gcc compiler; otherwise, if you are using an mswin32 build, you should use Visual C++. In any case, after you create the *.c file you wish to compile, you need to create a flexible extconf.rb file, by which I mean you need to set a few options for the target compiler in the extconf.rb file. Something like: require 'mkmf' case PLATFORM when /mswin32/ $CFLAGS='/W3' when /mingw/ $CFLAGS='-DNONAMELESSUNION' $LDFLAGS='-L/usr/local/lib' when /cygwin/ $CFLAGS='-DNONAMELESSUNION' $LDFLAGS='-L/usr/local/lib' end Then if you have any external libraries or headers you want to link to (which it sounds like you don't), then you can do the have_libary() and/or have_header() thing. You can also have certain directories pointed to as command line options if you suspect the user might not have a particular library in their path. For instance, I created a native extension to the CA COOL:Gen API, a very low-level interface to their data-modeling and code generation tool, so that I could script against the API in Ruby using high-level Ruby abstractions. While the user who wants to compile this extension probably has their COOL:Gen directory in their path, just in case they don't, I allow for them to specify the directory at the command line using ruby extconf.rb --with-coolgen-dir="C:\COOL\Gen" by merely including the line dir_config('coolgen') in my extconf.rb. My entire extconf.rb file looks like this: ------------------- require 'mkmf' def print_usage # omitted for brevity end case PLATFORM when /mswin32/ $CFLAGS='/W3' when /mingw/ $CFLAGS='-DNONAMELESSUNION' $LDFLAGS='-L/usr/local/lib' when /cygwin/ $CFLAGS='-DNONAMELESSUNION' $LDFLAGS='-L/usr/local/lib' end dir_config('coolgen') if have_library("eapi32w",nil) and have_header('eapidef.h') then create_makefile('coolrapi') else print_usage end -------------------- That's it! and it works beautifully whether I'm using cygwin or mswin32 as my distro de jour. all I need to do is call make or nmake as follows: (n)make all (n)make install I have compiled both the cygwin and the mswin32 distributions on my machine (I named the mswin32 executable rb32 to avoid name conflicts). so if I run: ruby extconf.rb it will generate a cygwin-friendly makefile, whereas if I run rb32 extconf.rb it will generate a mswin32-friendly makefile. Now it seems to me based on your problem that you were using the wrong compiler options and/or make utility for the distro you are using. If having generated my Makefile using rb32 (the mswin32 distro) I attempt to use 'make all' instead of 'nmake all', I get: make: ***No rule to make target 'coolrapi.obj', needed by 'coolrapi.so'. Stop. Which looks alot like your error. But if I use 'nmake all' it compiles just fine. So - in the absence of more information about your problem - I suspect you need to set different $CFLAGS in your extconf.rb file depending on the distro used to gen the makefile. In your case you want to be sure to set the $CFLAGS and $LDFLAGS as illustrated above before you gen the makefile with the cygwin distro of ruby. I cover compiling Ruby and writing Ruby C extensions extensively in the Sam's "Ruby Developer Handbook" that Rich Kilmer and Dana Moore and I are working on in chapter 9, "20,000 Leagues Under the C", where I also explore getting Ruby to compile with compilers other than cygwin and mswin (namely, borland's free compiler). It should be out next January. :) Sincerely, Bob Calco % -----Original Message----- % From: repeater [mailto:repeater@lucentprimate.cjb.net] % Sent: Sunday, May 26, 2002 7:34 AM % To: ruby-talk ML % Subject: compilation ignorance % % % i am using Ruby 1.6.6 win pragprog distro % i haven't moved much in C circles, so please help out with obvious % conceptual errors too. (the newbie speaks) % % i have a need to compile a library, in my case NArray % (sideline: % i've tried the accompanying extconf.rb, the cygwin make, but it % fails with: % "make: *** No rule to make target `narray.obj', needed by `narray.so'. % Stop." % hmmm. not much help that) % % this may or may not have to do with me using the pragprog distro % (cygwin gcc % not working well with msvc, i don't know) % % so i please ask someone to quench my thirst: % % (the ancient art of compiling...the where the how) or % (the secret place where windows compiled libraries run free) % % thank you % % regards % repeater % %