#1165 swig doesn't work with Octave

closed-fixed
octave (7)
5
2011-05-21
2011-05-11
dynamphorous
No

I have opened this on stack overflow as well at http://stackoverflow.com/questions/5887494/using-swig-to-create-octave-file But thus far no responses there of any merit. Here is what happens. Even the most simple C or C++ program wont compile for Ocatve using swig. The documentation appears to be wrong for this, so either I'm doing something wrong, or the documentation is out of date. The commands I use are:

swig -octave -o swig_test_wrap.cpp swig_test.i
mkoctfile swig_test_wrap.cpp swig_test.c

The order of the -o and the .i file is backwards from the docs, but otherwise it complains that swig_test.i is an unrecognized command when entered the same way as the documentation.

The other thing it complains about is mkoctfile returns 4 errors consistently

swig_test_wrap.cpp:1449:24: error: invalid covariant return type for 'virtual Octave_map octave_swig_type::map_value() const'
/usr/include/octave-3.4.0/octave/../octave/ov-base.h:560:22: error: overriding 'virtual octave_map octave_base_value::map_value() const'
swig_test_wrap.cpp:1657:24: error: invalid covariant return type for 'virtual Octave_map octave_swig_ref::map_value() const'
/usr/include/octave-3.4.0/octave/../octave/ov-base.h:560:22: error: overriding 'virtual octave_map octave_base_value::map_value() const'

I am assuming that this is a SWIG bug, not an octave bug, mostly because SWIG wants to natively produce a .cxx file, which when you feed it the -octave parameter, it seems that someone should have known that mkoctfile cant take a file of type .cxx. It only works with .cpp .C and .cc.

The contents of my test_swig.c and test_swig.i are not important to include, since they are just the example code given in the SWIG documentation. And I have tried little changes too, to no avail.

Discussion

  • Karl Wette
    Karl Wette
    2011-05-13

    Hi,

    You do need to put the .i file at the end of the command line - this seems to be an odd quirk in how SWIG processes its command line arguments. The .cxx problem is more a bug in mkoctfile, which for some reason doesn't recognize .cxx as a valid extension for a C++ file.

    As for the compilation errors - I'm guessing you're using a newish version of Octave? I think at some point the class "Octave_map" was renamed to "octave_map" in Octave - but this hasn't been changed in the SWIG Octave module yet. You could try adding this to your .i file:

    %begin %{
    #define Octave_map octave_map
    %}

    If that doesn't work, try downgrading to v3.2.4, which I've been using successfully with SWIG.

    Cheers,
    Karl

    PS: the SWIG mailing list might be a better place to address questions in future (http://www.swig.org/mail.html)

     
  • dynamphorous
    dynamphorous
    2011-05-13

    • status: open --> open-accepted
     
  • dynamphorous
    dynamphorous
    2011-05-13

    Karl,
    Thank you for responding to me. I had tried using the mailing list a few days ago, and I have also tried stackoverflow and a few other resources. You are by far the most helpful thus far.

    So I tried what you suggested, and I just got a bunch of errors telling me that octave_map is not defined. You were compltely correct about me using a rather new version of Octave, (3.4.0) and when I downgraded to 3.2.4-r3 I found that it works just fine. Thank you for your time, I appreciate the help.

    Sincerely
    -Dan

     
  • William Fulton
    William Fulton
    2011-05-21

    • status: open-accepted --> closed-fixed
     
  • William Fulton
    William Fulton
    2011-05-21

    Octave 3.4.0 is now working with swig-2.0.4