Forum: Ruby SWIG toy example problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
72003cf388f6f7f95b433de3df9ccd38?d=identicon&s=25 Larrytheliquid (Guest)
on 2007-03-24 21:31
(Received via mailing list)
I'm having a bit of trouble trying to use SWIG to wrap a simple C++
header
file, as follows:

'MyTest.h'
----------
#define SUCCESS 1
----------

'myTest.i'
----------
%include MyTest.h

%module myTest
%{
#include "MyTest.h"
%}
---------

swig -c++ -ruby myTest.i

g++ -c myTest_wrap.cxx -I/usr/lib/ruby/1.8/i386-cygwin

g++ -shared myTest_wrap.o -lruby -o myTest.so

$ irb
irb(main):001:0> require 'myTest'
=> true
irb(main):002:0> MyTest::SUCCESS
NameError: uninitialized constant MyTest::SUCCESS
        from (irb):3
        from :0
irb(main):004:0> MyTest.constants
=> []
irb(main):005:0>
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-03-26 09:46
(Received via mailing list)
On 3/24/07, Larrytheliquid <larrytheliquid@gmail.com> wrote:
> %include MyTest.h
>
> => []
> irb(main):005:0>
>

Hi,

somehow works for me. To check, have a look at the end of the
generated file - there should be a line saying
rb_define_const(mMyTest,"SUCCESS", INT2NUM(1));

SWIG processor by default ignores #include (to enable them use
--includeall) but this is not your case, as you used %include instead.

I'm using SWIG 1.3.27, as the newer ones converted ruby support to
unified templates, and I couldn't get our hacks to work with them yet.

Jano
72003cf388f6f7f95b433de3df9ccd38?d=identicon&s=25 Larrytheliquid (Guest)
on 2007-03-27 18:51
(Received via mailing list)
Hi Jano,

Good call on checking for rb_define_const... it wasn't there. I
eventually
found out that the version I was using was 1.3.29, which did not seem to
work. After using 1.3.31 everything worked well.

Thanks.
This topic is locked and can not be replied to.