Quantcast
Channel: apocryph.org » ruby
Viewing all articles
Browse latest Browse all 10

Getting FXRuby going with Ruby 1.9.1 and the new RubyInstaller

$
0
0

I’ve long resented the fact that the Ruby one-click installer for Windows uses Ruby binaries built with Visual C++ 6.0, which being ancient AND broken is very much teh suck. Thankfully, Luis Lavena is working on a new Windows installer for Ruby 1.9.x, the so-called RubyInstaller, which uses binaries built with MinGW. I wish he’d use the free version of Visual C++ 2008, since that IS the definitive compiler for Windows, but there are some licensing gotchas there to worry about, and anything is better than VC6.

Anyway, I downloaded the latest preview release of the installer, and the separate DevKit tarball, which I extracted into my Ruby install directory (which is _not_ c:\ruby; I hate dumping stuff in the root of the file system). I then wanted to get FXRuby, the Ruby bindings for the FOX GUI toolkit, working in this environment. Not easy. My experience follows.

Directories

I use a non-standard directory layout.  I’ll make reference to it in the steps below.  You obviously don’t have to use my layout.

c:\work – Where it all happens

c:\work\sourcecode – Where I extract source tarballs.  For example, zlib-1.2.3 is extracted to c:\work\sourcecode\zlib-1.2.3

c:\work\tools – Where I install the built libraries.  For example, zlib-1.2.3 is installed to c:\work\tools\zlib-1-2.3 (with make install creating subdirectories like lib and include).

c:\work\tools\ruby19 – Where I installed Ruby 1.9

Installing Ruby

I grabbed the latest preview1 installer here. At the time of this writing, it was ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32].

I also grabbed the DevKit tarball from the same location. At the time, it was Development Kit 3.4.5r3 (MinGW 3.4.5 + MSYS 1.0.11)

I ran the installer and installed to c:\work\tools\ruby19. Note this non-standard install path; it bites me in the ass later.

Downloading FOX source

I grabbed the latest stable FOX source tarball, 1.6.36, and extracted it to c:\work\tools\fox-1.6.36. I have to get FOX built before I can even think about the FXruby bindings. The challenge is I need to build it using the MinGW environment that’s part of the Ruby DevKit I downloaded. I’ve never used MinGW, so this should be interesting.

Running Build Environment

Unless otherwise specified, all the subsequent commands are run from the Ruby build environment, which can be accessed by the ‘Start Command Prompt With Ruby’ shortcut.

Building FOX Dependencies

I put all the dependencies for FOX in C:\work\sourcecode.  I’ll build them one by one

zlib

sh configure --prefix=c:/work/tools/zlib-1.2.3
make
make install

jpeg

mkdir c:\work\tools\jpeg-6b\bin
mkdir c:\work\tools\jpeg-6b\man\man1
mkdir c:\work\tools\jpeg-6b\include
mkdir c:\work\tools\jpeg-6b\lib
sh configure --prefix=c:/work/tools/jpeg-6b --enable-shared --enable-static
make
make install (this fails with an error trying to install the library)
copy libjpeg.a c:\work\tools\jpeg-6b\lib\libjpeg.a

libpng

set CPPFLAGS=-Ic:/work/tools/zlib-1.2.3/include
set LDFLAGS=-Lc:/work/tools/zlib-1.2.3/lib
sh configure --prefix=c:/work/tools/libpng-1.2.16
make
make install

tiff

sh configure --prefix=c:/work/tools/tiff-3.8.2 --with-zlib-include-dir=c:/work/tools/zlib-1.2.3/include --with-zlib-lib-dir=c:/work/tools/zlib-1.2.3/lib --with-jpeg-include-dir=c:/work/tools/jpeg-6b/include --with-jpeg-lib-dir=c:/work/tools/jpeg-6b/lib
make
make install

Building FOX 1.6 itself

Brace yourself.  The FOX build is REALLY SLOW.  As in, start it at night and check on it in the morning slow.


set "CPPFLAGS=-Ic:/work/tools/jpeg-6b/include -Ic:/work/tools/libpng-1.2.16/include -Ic:/work/tools/tiff-3.8.2/include -Ic:/work/tools/zlib-1.2.3/include"
set "LDFLAGS=-Lc:/work/tools/jpeg-6b/lib -Lc:/work/tools/libpng-1.2.16/lib -Lc:/work/tools/tiff-3.8.2/lib -Lc:/work/tools/zlib-1.2.3/lib"
sh configure --enable-jpeg --enable-png --enable-tiff --enable-zlib
make
make install prefix=c:/work/tools/fox-1.6.36

Preparing FXRuby gem

Of course, there is no binary gem for FXRuby compiled for MinGW, so you must build it from source.  Unfortunately, the source gem as of this writing is not compatible with MinGW.  If you try to install it, you’ll get this:


In file included from c:/work/Tools/ruby19/include/ruby-1.9.1/ruby/missing.h:22,
from c:/work/Tools/ruby19/include/ruby-1.9.1/ruby/ruby.h:1125,
from c:/work/Tools/ruby19/include/ruby-1.9.1/ruby.h:32,
from librb.c:355:
c:/work/Tools/ruby19/devkit/gcc/3.4.5/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/time.h:27: error: redefinition of `struct timezone'
c:/work/Tools/ruby19/devkit/gcc/3.4.5/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/time.h:40: error: conflicting types for 'gettimeofday'
c:/work/Tools/ruby19/include/ruby-1.9.1/ruby/win32.h:248: error: previous declaration of 'gettimeofday' was here
c:/work/Tools/ruby19/devkit/gcc/3.4.5/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/time.h:40: error: conflicting types for 'gettimeofday'
c:/work/Tools/ruby19/include/ruby-1.9.1/ruby/win32.h:248: error: previous declaration of 'gettimeofday' was here
make: *** [librb.o] Error 1

Fortunately, it’s very easy to patch.

First, download the FXRuby 1.6.19 source tarball (NOT source gem; as noted it won’t work).  I extracted it toc:\work\sourcecode\fxruby-1.6.19.

In that directory, edit the ext/fox16/extconf.rb file.  Find the do_cygwin_setup method (around line 80).  Find this line:

have_header("sys/time.h")

And comment it out, so it looks like this:

#have_header("sys/time.h")

Then find the line:

dir_config('fxscintilla', '/usr/local/include/fxscintilla', '/usr/local/lib')

and under it add the following:

# Need to add this so it can find dependent libs under Windows
dir_config('zlib')
dir_config('tiff')
dir_config('jpeg')
dir_config('png')

Next, edit the FXRuby.cpp file in the same directory. Find the line:

extern "C" void Init_fox16(void) {

and change it to:

extern "C" void __declspec(dllexport) Init_fox16(void) {

Then build the source gem from the fxruby-1.6.19 directory:

rake build_src_gem

This will create fxruby-1.6.19.gem. Install it now:


gem install fxruby-1.6.19.gem -- --with-fox-include=c:/work/tools/fox-1.6.36/include/fox-1.6 --with-fox-lib=c:/work/tools/fox-1.6.36/lib --with-zlib-include=c:/work/tools/zlib-1.2.3/include --with-zlib-lib=c:/work/tools/zlib-1.2.3/lib --with-tiff-include=c:/work/tools/tiff-3.8.2/include --with-tiff-lib=c:/work/tools/tiff-3.8.2/lib --with-png-include=c:/work/tools/libpng-1.2.16/include --with-png-lib=c:/work/tools/libpng-1.2.16/lib --with-jpeg-include=c:/work/tools/jpeg-6b/include --with-jpeg-lib=c:/work/tools/jpeg-6b/lib

The gem doesn’t copy the dependent files into the right place, so you have to do that yourself:

copy c:\work\tools\libpng-1.2.16\bin\libpng-3.dll c:\work\Tools\ruby19\bin
copy c:\work\tools\tiff-3.8.2\bin\libtiff-3.dll c:\work\Tools\ruby19\bin

Once the gem is installed, run one of the samples to make sure it worked:

ruby examples/hello.rb

If you’re lucky and the planets are in alignment, you’ll get a little window with “Hello World” in it. Yay.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images