Porting from unix to mingw

Hello,

i’m regularly using ruby on a win32 environment, and i’d like to know if
any of you has some general indications on how to build extensions in a
MINGW32 environment, so as to get mswin compatible binaries without the
cost of a Visual Studio Licence.

I found that WATANABE Hirofumi, aka eban, has ported many packages and
gives access to compiled binaries [1] and I believe he built these
packages on a linux box.

If these indication allowed me to cross compile from linux to windows,
it would be enough for me. I’d just like to be able to have the
equivalent ability on both platforms.

TIA,

1: http://www.ruby-lang.org/~eban/ruby/binaries/mingw/

···


Pierre Baillet
Our bodies are given life from the midst of nothingness. Existing where there
is nothing is the meaning of the phrase, “form is emptiness.” That all things
are provided for by nothingness is the meaning of the phrase, “Emptiness is
form.” One should not think that these are two separate things.
Ghost Dog - The Way of the Samouraï

I can only give an extremely general indication, and that is that
everything should work fine. The dependencies are:

  • gcc
  • make
  • ruby
    and they’re all present if (perhaps not only if) you build Ruby with
    mingw (that way, Ruby’s insternal config knows what compiler, what
    directories, etc.)

I vaguely remember having some trouble compiling stuff under mingw
when my “ruby” was the native windows one. Building Ruby under mingw
is easy and should lead to the path of happiness.

Gavin

···

On Tuesday, February 18, 2003, 10:41:29 AM, Pierre wrote:

Hello,

i’m regularly using ruby on a win32 environment, and i’d like to know if
any of you has some general indications on how to build extensions in a
MINGW32 environment, so as to get mswin compatible binaries without the
cost of a Visual Studio Licence.

Hello,

I probably wasn’t clear enough as what i want is to build binary extensions
(such as xmlparser) with MINGW that are compatible with the mswin32
build.

Suppose I have a working mswin32 ruby installation, and a ruby extension
source. How can i use and ask extconf.rb so that it builds a .so using
MINGW that works with my mswin32 ruby.

···

On Tue, Feb 18, 2003, Pierre Baillet wrote:

Hello,

i’m regularly using ruby on a win32 environment, and i’d like to know if
any of you has some general indications on how to build extensions in a
MINGW32 environment, so as to get mswin compatible binaries without the
cost of a Visual Studio Licence.

I found that WATANABE Hirofumi, aka eban, has ported many packages and
gives access to compiled binaries [1] and I believe he built these
packages on a linux box.

If these indication allowed me to cross compile from linux to windows,
it would be enough for me. I’d just like to be able to have the
equivalent ability on both platforms.

TIA,

1: http://www.ruby-lang.org/~eban/ruby/binaries/mingw/

Pierre Baillet
Our bodies are given life from the midst of nothingness. Existing where there
is nothing is the meaning of the phrase, “form is emptiness.” That all things
are provided for by nothingness is the meaning of the phrase, “Emptiness is
form.” One should not think that these are two separate things.
Ghost Dog - The Way of the Samouraï


Pierre Baillet
If it doesn’t work, force it. If it breaks, it needed replacing anyway.

Maybe you already got a detailed answer but a very simple solution, that I
use myself, is:

  1. Install cygwin, www.cygwin.com, and make sure you install gcc 3.2 and
    mingw includes (check ‘develop’ subcategory during cygwin install and
    make sure you check all packages with mingw in the name)

  2. downloaded the source for your Ruby version of choice, unpack and go
    in there

  3. autoconf

  4. ./configure --with-gcc=‘gcc -mno-cygwin’ --enable-shared

  5. make
    make test
    make install

  6. dl, unpack and build your ruby extensions the normal way

Note that for ruby extensions that rely on external libs you have to
separately build and install the libs since the cygwin-installed ones
cannot be used with your mingw ruby. Thus you typically need to use the
“–with-xxx-dir=your/path/here” option when creating makefiles with
extconf.rb.

Hope this helps!

/Robert Feldt

···

On Tue, 18 Feb 2003, Gavin Sinclair wrote:

On Tuesday, February 18, 2003, 10:41:29 AM, Pierre wrote:

Hello,

i’m regularly using ruby on a win32 environment, and i’d like to know if
any of you has some general indications on how to build extensions in a
MINGW32 environment, so as to get mswin compatible binaries without the
cost of a Visual Studio Licence.

I just did the procedure yesterday :slight_smile:

Downloaded and installed latest MinGw (2.0.0) & MSYS (1.0.9) without
cygwin package.

The only trick in building Ruby with MinGW was to replace the LDSHARED
line with: dllwrap --target=mingw32 --export-all -s

and after compiling (on Win98) I had to run: make ruby.exe since it was
not created. Make test reports success.

I found this answer in the archives.

Building Swig went without any problem.

Sincerely,
Gour

···

On Tuesday, February 18, 2003, 10:41:29 AM, Pierre wrote:

i’m regularly using ruby on a win32 environment, and i’d like to know if
any of you has some general indications on how to build extensions in a
MINGW32 environment, so as to get mswin compatible binaries without the
cost of a Visual Studio Licence.


Gour
gour@mail.inet.hr
Registered Linux User #278493

I’ve got these C++ classes:

class CSITick {
public:
unsigned long date;
float open;
float high;
float low;
float close;
long volume;
};
class CSIChart {
public:
CSITick* getTick(long date); // CAN return NULL!!!
CSITick* ticks;
long numticks;
//…
};

where ‘ticks’ is an array of CSITick’s, created with:
ticks = new CSITick[numticks];

I can't seem to figure out how to make SWIG access this

‘ticks’ pointer as if it were an Array in Ruby, with length
equal to numticks. I would like it to be read-only as well.

The '%typemap' SWIG directive doesn't seem right, as

this is the only place where I want to treat a CSITick* as an
Array… otherwise, I would like a CSITick* to just be a reference
to an instance of CSITick. Am I making any sense?

I'm using SWIG-1.3.17 and ruby 1.6.8 (2002-12-24) [i586-mswin32]

on Windows XP.

Thanks!
					-- Glenn Lewis

I think I solved this one with a hack… in the CSIChart.h file,
I put:

···

=================
#ifndef SWIG
CSITick* ticks;
#endif

and then I added to the RubyStock.i file:

%include “CSIChart.h”
%extend CSIChart {
CSITick* ticks(int index) {
while (index < 0) index += self->numticks; // wrap-around
if (index >= self->numticks) {
printf(“ERROR: index (%d) out of range for ticks array: 0…%d\n”,
index, self->numticks);
return 0;
}
return &self->ticks[index];
}
};

This works, but is there a way to turn this into a Ruby Array
so that ‘ticks’ could be accessed with the ‘’ notation?

Thanks!
– Glenn Lewis

Glenn M. Lewis wrote:

I've got these C++ classes:

class CSITick {
public:
unsigned long date;
float open;
float high;
float low;
float close;
long volume;
};
class CSIChart {
public:
CSITick* getTick(long date); // CAN return NULL!!!
CSITick* ticks;
long numticks;
//…
};

where ‘ticks’ is an array of CSITick’s, created with:
ticks = new CSITick[numticks];

I can't seem to figure out how to make SWIG access this

‘ticks’ pointer as if it were an Array in Ruby, with length
equal to numticks. I would like it to be read-only as well.

The '%typemap' SWIG directive doesn't seem right, as

this is the only place where I want to treat a CSITick* as an
Array… otherwise, I would like a CSITick* to just be a reference
to an instance of CSITick. Am I making any sense?

I'm using SWIG-1.3.17 and ruby 1.6.8 (2002-12-24) [i586-mswin32]

on Windows XP.

Thanks!
                    -- Glenn Lewis

Glenn M. Lewis wrote:

I think I solved this one with a hack… in the CSIChart.h file,
I put:

#ifndef SWIG
CSITick* ticks;
#endif

and then I added to the RubyStock.i file:

%include “CSIChart.h”
%extend CSIChart {
CSITick* ticks(int index) {
while (index < 0) index += self->numticks; // wrap-around
if (index >= self->numticks) {
printf(“ERROR: index (%d) out of range for ticks array: 0…%d\n”,
index, self->numticks);
return 0;
}
return &self->ticks[index];
}
};

This works, but is there a way to turn this into a Ruby Array
so that ‘ticks’ could be accessed with the ‘’ notation?

I think I would change the %extend-ed version of ticks() to look
something like this instead:

 %extend CSIChart {
   VALUE ticks() const {
     VALUE ary = rb_ary_new();
     for (long i = 0; i < self->numticks; i++) {
       VALUE tickObj =
         SWIG_NewPointerObj(self->ticks[i], SWIGTYPE_p_CSITick, 0);
       rb_ary_push(ary, tickObj);
     }
     return ary;
   }
 };

Hope this helps,

Lyle