Hi there,

I'm trying to create a C extension that compiles for both Ruby 1.8 and
1.9. As far as I know, there should be the macros RUBY_VERSION_MAJOR,
RUBY_VERSION_MINOR and RUBY_VERSION_TINY to check with which Ruby
version we're compiling, and they should be defined in the header
"ruby/version.h". But there's the problem: That file just doesn't exist
in my Ruby installations. Wheather I try to compile with 1.8.7 or 1.9.1,
I get:

fatal error: ruby/version.h: No such file or directory

This simple C extension demonstrates the issue:
-----------------------------------------
#include "ruby.h"
#include "ruby/version.h"

VALUE Foo;

static VALUE m_abc(VALUE self)
{
  #if RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 9
  printf("Using 1.9\n");
  #else
  printf("Using 1.8\n");
  #endif
  return Qnil;
}

void Init_abc()
{
  Foo = rb_define_module("ABC");
  rb_define_module_function(Foo, "abc", m_abc, 0);
}
-----------------------------------------

If I comment out '#include "ruby/version.h"' I don't get compile errors,
but when I run the program, I always get "Using 1.8" regardless which
Ruby the extension was compiled for.

Here's my systems configuration:
Windows Vista 32-Bit
ruby -v: ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
ruby18 -v: ruby 1.8.7 (2009-12-24 patchlevel 248) [i386-mingw32]
gcc --version: gcc.exe (GCC) 4.5.0
(I have a separate MinGW + MSYS installation, not the Development Kit
from the RubyInstaller)

I installed 1.9 via the RubyInstaller's 7z and compiled 1.8 myself.

Any hints on how to find out the Ruby version from C?

Marvin
-- 
Posted via http://www.ruby-forum.com/.