FYI, here is a MEX file that can be compiled on a system that does not
have either Octave or Matlab and that can be run in either program:
typedef void mxArray;
extern void mexPrintf (const char *fmt, ...);
extern mxArray *mxDuplicateArray (const mxArray *v);
void
mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int i;
if (nlhs == nrhs)
{
mexPrintf ("copying inputs to outputs\n");
for (i = 0; i < nrhs; i++)
plhs[i] = mxDuplicateArray (prhs[i]);
}
}
Just compile with gcc -shared -fPIC -o foo.mex foo.c (you may need to
change the extension to mexglx so that Matlab can load it).
Since mxArray is an opaque type (all you ever need to use is a
pointer to it, and you never access contents directly) you don't need
to know its actual definition. That's why the void typedef works and
you don't have to include mex.h for this struct definition. You can
get the prototypes for the most of the interface from the
documentation. The only sticking points are a few typedefs like
mxLogical, mxChar, mwSize, and mwIndex. For those, you can probably
figure out what they are by trial and error. Oh, and the only other
thing is you should avoid character data since Octave uses 8 bit
characters internally, but I think Matlab uses something wider. So
direct character manipulation will probably crash either Matlab or
Octave (depending on what actual data type you choose for mxChar) or
I expect you will at least get some jumbled character strings.