help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Info on calling C from octave


From: James Haefner
Subject: Info on calling C from octave
Date: Wed, 19 Sep 2007 10:57:03 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060717 Debian/1.7.13-0.2ubuntu1

Hi, I'm new to calling C (not C++) functions from octave and need some basic help:

(1) Is there a good tutorial that describes the uses/differences between
mex and mkoctfile and the general strategy for calling C functions in external libraries?

(2) In the mean time, can anyone explain these results from octave_2.9.6 on a linux (ubuntu 6.10) machine:

The following C++ file (hello2oct.cc) works correctly when operated on by mkoctfile on the system command line: "mkoctfile hello2oct.cc"
#include <octave/oct.h>
DEFUN_DLD (hello2oct, args, nargout,
       "Hello World Help String")
     {
       int nargin = args.length ();
       octave_stdout << "Hello World has " << nargin
             << " input arguments and "
             << nargout << " output arguments.\n";
       return octave_value_list ();
     }

The following C file (foobar.c) fails ("mkoctfile foobar.c") with the appended error messages:
#include <octave/oct.h>
DEFUN_DLD (foobar, args, nargout,
       "Hello World Help String")
     {
       return octave_value_list ();
     }

(same result if I remove the return line).

Errors:
In file included from /usr/include/octave-2.9.6/octave/mx-base.h:29,
                 from /usr/include/octave-2.9.6/octave/Matrix.h:31,
                 from /usr/include/octave-2.9.6/octave/oct.h:34,
                 from foobar.c:1:
/usr/include/octave-2.9.6/octave/MatrixType.h:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Matrix' /usr/include/octave-2.9.6/octave/MatrixType.h:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ComplexMatrix' /usr/include/octave-2.9.6/octave/MatrixType.h:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SparseMatrix' /usr/include/octave-2.9.6/octave/MatrixType.h:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SparseComplexMatrix'
/
... followed by many similar lines

Obviously, I'm missing some fundamental concepts here, so any help will be appreciated.


Jim Haefner


reply via email to

[Prev in Thread] Current Thread [Next in Thread]