mxCreateLogicalScalar
John W. Eaton
jwe at bevo.che.wisc.edu
Tue Jun 10 12:56:01 CDT 2008
On 10-Jun-2008, E. Joshua Rigler wrote:
| Bug report for Octave 3.0.1 configured for x86_64-unknown-linux-gnu
|
| Description:
| -----------
|
| After successfully compiling some MEX C code, and running it through
| several basic operations to confirm it was working in general, I got
| the following error when the function attempted to define an mxLogical
| variable from a boolean operation:
|
| octave: symbol lookup error:
| /home/jrigler/octave/mfitsio/fits_read_header.mex: undefined symbol:
| mxCreateLogicalScalar
|
| The code is simple enough; it just compares a character scalar (f,
| read in successfully from a text file) with different characters that
| might be used to define a logical variable (e.g., 'T', 'F', 't', 'f').
| It looks like:
|
| if (f == 'T' || f == 'F' || f == 't' || f == 'f')
| {
| retval = mxCreateLogicalScalar (f == 'T' || f == 't');
| }
|
| I believe this works in ML (I don't currently have access to ML to
| confirm this, but the code has been used successfully for several
| years). Also, I looked at liboctinterp.so using the nm utility. The
| mxCreateLogicalScalar symbol is there, but its name is mangled (other
| mxCreate*Scalar symbols are NOT mangled, if that makes a difference).
|
| I noticed that mxCreateLogicalScalar is defined differently in
| mexproto.h and mex.cc (its input argument is type int in the former,
| and mxLogical in the latter). However, I tried modifying mexproto.h
| accordingly, and rerunning mkoctfile --mex, but nothing changed. I'm
| pretty much out of ideas at this point.
The problem is that because the declaration is wrong when the Octave
is built, the extern "C" part of the declaration is missing, so the
function is defined with a C++ mangled name.
I've fixed the declaration in the Octave sources.
Correcting the declaration and rebuilding Octave should fix the
problem.
Or, you can work around the problem by defining your own function to
create a logical scalar given a value. For example
#include "mex.h"
mxArray *
my_mx_create_logical_scalar (mxLogical val)
{
mxArray *retval = mxCreateLogicalMatrix (1, 1);
mxLogical *data = mxGetLogicals (retval);
data[0] = val;
return retval;
}
void
mexFunction (int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
plhs[0] = my_mx_create_logical_scalar (1);
}
jwe
More information about the Bug-octave
mailing list