mercredi 28 octobre 2020

Calling Octave interpreter from C++ - Problems compiling and running example

I'm trying to implement calling octave from C, as per the example shown in this answer Call GNU Octave functions in C?

I'm trying this in Nebeans on Linux.

I've created the files calloctave.cc, calloctave.h, main.c and myfunction.m as per the example. Pointed the links and includes to the correct places (in my case /usr/include/octave-5.2.0/octave/ and /usr/lib64/octave/5.2.0 ). Ive chosen C++11 as the standard. In the code, there are no errors highlighted and it seems to find everything it needs, and nothing is highlighted as missing.

When I try to compile it, I just get a series of errors as follows....

cd '/home/arwel/NetBeansProjects/callOctave_new'
/bin/gmake -f Makefile CONF=Debug
"/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/arwel/NetBeansProjects/callOctave_new'
"/bin/gmake"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/libcallOctave_new.so
gmake[2]: Entering directory `/home/arwel/NetBeansProjects/callOctave_new'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/calloctave.o.d"
g++    -c -g -I/usr/include/octave-5.2.0/octave -include /usr/include/octave-5.2.0/octave/mex.h -std=c++11 -fPIC  -MMD -MP -MF "build/Debug/GNU-Linux/calloctave.o.d" -o build/Debug/GNU-Linux/calloctave.o calloctave.cc
In file included from /usr/include/octave-5.2.0/octave/Cell.h:33:0,
                 from /usr/include/octave-5.2.0/octave/gtk-manager.h:32,
                 from /usr/include/octave-5.2.0/octave/interpreter.h:36,
                 from calloctave.cc:7:
/usr/include/octave-5.2.0/octave/ov.h:52:7: error: using typedef-name ‘mxArray’ after ‘class’
 class mxArray;
       ^
In file included from <command-line>:0:0:
/usr/include/octave-5.2.0/octave/mex.h:55:14: note: ‘mxArray’ has a previous declaration here
 typedef void mxArray;
              ^
In file included from /usr/include/octave-5.2.0/octave/ov.h:62:0,
                 from /usr/include/octave-5.2.0/octave/Cell.h:33,
                 from /usr/include/octave-5.2.0/octave/gtk-manager.h:32,
                 from /usr/include/octave-5.2.0/octave/interpreter.h:36,
                 from calloctave.cc:7:
/usr/include/octave-5.2.0/octave/ov-base.h:57:7: error: using typedef-name ‘mxArray’ after ‘class’
 class mxArray;
       ^
In file included from <command-line>:0:0:
/usr/include/octave-5.2.0/octave/mex.h:55:14: note: ‘mxArray’ has a previous declaration here
 typedef void mxArray;
              ^
calloctave.cc: In function ‘int mexCallOctave(int, mxArray**, int, mxArray**, const char*)’:
calloctave.cc:26:15: error: ‘mxArray’ is not a class, namespace, or enumeration
     args(i) = mxArray::as_octave_value (argin[i]);
               ^
calloctave.cc:42:41: error: invalid use of ‘mxArray {aka void}’
       argout[i] = new mxArray (retval(i));
                                         ^
calloctave.cc: In function ‘void free_arg_list(int, mxArray**)’:
calloctave.cc:56:29: warning: deleting ‘mxArray* {aka void*}’ is undefined [enabled by default]
             delete arglist[i];
                             ^
gmake[2]: *** [build/Debug/GNU-Linux/calloctave.o] Error 1
gmake[2]: Leaving directory `/home/arwel/NetBeansProjects/callOctave_new'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/arwel/NetBeansProjects/callOctave_new'
gmake: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

It seems to be not understanding the mex interface in some way. I'm not very knowledgeable about c/c++, so am at a loss as to how to proceed here. What could be causing these errors and how might I resolve them??

Cheers, Arwel

Aucun commentaire:

Enregistrer un commentaire