From: Daniel Berger Date: 2006-12-05T07:00:04+09:00 Subject: Re: Swig, Ruby, C++ question Jan Svitok wrote: > On 12/4/06, Daniel Berger wrote: > > Hi all, > > > > Solaris 10 > > swig 1.3.21 > > Sun Studio 11 > > > > I'm trying my hand at SWIG here. I've read over > > http://www.swig.org/Doc1.3/Ruby.html, but I'm confused as to how to > > setup the interface file so that I get a class. I don't want a > > module, if possible. > You need to include the header in the interface file. In fact, you > need to include it twice: once for SWIG to parse it and create the > wrapper .c/.cxx/.cpp file, and second time in the wrapper itself to be > compilable. > > /* first time for swig */ > %include polygon.h This works, thanks! > /* second time for c compiler */ > %{ > #include "polygon.h" > %} If this is supposed to generate a '#include "polygon.h"' entry within the .cxx file, it doesn't seem to work. I can stuff it in there manually easily enough, but I'd like to know what I'm doing wrong. > you can replace these two with (in the latest version at least, so YMMV) > > %inline %{ > #include "polygon.h" > %} I had no luck with this either. It didn't cause an error, it just didn't seem to do anything. > A single #include might be enough. Try and if not, use the above form. > > If the .i file is not too much complicated, you can merge it with the > h file by enclosing SWIG specifics in #ifdef SWIG, e.g. > // polygon.h > #ifdef SWIG > %module polygon > #endif The .h file I ultimately want to wrap is not under my control, so this won't be an option. Regards, Dan