Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624260
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:06:17+00:00 2026-05-22T03:06:17+00:00

I’m trying to use SWIG to create a Octave function. But even the most

  • 0

I’m trying to use SWIG to create a Octave function. But even the most basic example code seems to fail before I even get the chance to get it into octave. I am not sure if I should be concerned that swig creates a extension type for the C++ source file (.cxx) it generates that mkoctfile doesn’t recognize (it only takes .C .cpp .cc, which seems like allot for swig to mess up that much and create what seems like the ONE extension for C++ it doesn’t support).

Any help from someone with more experience with this would be greatly appreciated!

The steps I have done are as follows:

swig -octave swig_test.i
mv swig_test_wrap.cxx swig_test_wrap.cpp <--- This is necessary because mkoctfile doesn't recognize the cxx type c++ code that swig generates
mkoctfile swig_test_wrap.cpp

This results in 4 errors consistantly:

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'

The source code of my outlandishly basic swig_test.c

int fact(int n) {
  if (n <= 1) return 1;
  else return n*fact(n-1);
}

int my_mod(int x, int y) {
   return (x%y);
}

Then the code of my wrapper inteface file swig_test.i

%module swig_test
%{
  extern int fact(int n);
  extern int my_mod(int x, int y);
%}

 extern int fact(int n);
 extern int my_mod(int x, int y);

___________________________________________________

UPDATE: May 9th 2011

So I still have not found a solution to this, and am starting to wonder if maybe these programs are out of date? The documentation most certainly is. Just as an example: the instructions say

 swig -octave swig_test.i -o swig_test_wrap.cxx

now that will certainly not work regardless, because mkoctfile wont take type cxx as stated before. Also, this command just is physically written wrong. As typed above, it returns the error.

 swig error : unrecognized option example.i
 use swig -help for available options

The command SHOULD be entered as:

 swig -octave -o swig_test_wrap.cpp swig_test.i

That WILL generate the swig_test_wrap.cpp file just as advertised. I would have thought there would be a -i option for input file in the argv of swig, but hey, now that I know that order matters here, someone must have just not updated the documentation when they changed something about how the function works.

So now, after running this command I have my swig_test_wrap.cpp file. Next I take that and try to execute

mkoctfile swig_test_wrap.cpp swig_test.c

Again, I get the same error as above: “invalid covariant return type” etc, however I also DO get a file swig_test.o out of the process. Just for fun, I then ran

mkoctfile swig_test.o

And lo and behold, this DOES generate a file called swig_test.oct. However when I went into octave and tried to load the file by running

octave:1>swig_test

I get the response error: ‘swig_test’ undefined near line 1 column 1

So as far as I can tell, I’m right back to square one. Anyone have any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:06:18+00:00Added an answer on May 22, 2026 at 3:06 am

    So it turns out that this issue is related to the version of octave that I was using. Octave version 3.4.0 doesn’t seem to work with swig yet. I got help on source-forge and once i downgraded to version 3.2.4-r3 it works perfectly.

    And it is a known bug that you have to use:

    swig -octave -o WRAPFILE.cpp INPUT.i
    

    and its a problem with mkoctfile that you have to use the .cpp extension, since they SHOULD accept the .cxx extension as it is a valid extension for C++ files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.