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
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?
fatal error: ruby/version.h: No such file or directory #if RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 9
Foo = rb_define_module(“ABC”);
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?
Most of the times you work around specific Ruby 1.9 features that
differ from 1.8, for example, encodings.
You have one example here:
As you can see, ruby/version.h has been deprecated.