简体   繁体   中英

Conversion of const size_t in mex

I tried to use the yaafe library from http://yaafe.sourceforge.net/manual/install.html . Everything is installed and works fine. However I would like to use the matlab interface and I tried to compile the yaafemex.cpp provided using the following command mex yaafemex.cpp but I have this error on Matlab

Building with 'Xcode Clang++'.
Error using mex
/Users/TMAC/Documents/MATLAB/Add-Ons/Collections/Yaafe/yaafemex.cpp:107:22: error: no matching function for call
to 'mxCreateNumericArray_730'
        mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL);
                            ^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:1111:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
                             ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:782:1: note: candidate function not viable: no known conversion
from 'int [2]' to 'const size_t *' (aka 'const unsigned long *') for 2nd argument
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag);
^
1 error generated.

Portions of code (I haven't changed the intitial code provided by yaafe library)

yaafemex.cpp

/* write data */
int dims[2] = {buf->info().size , buf->availableTokens()};
mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL); //line 107
double* featdataPtr = (double*) mxGetData(featdata);
buf->read(featdataPtr,buf->availableTokens());
buf->consumeTokens(buf->availableTokens());
mxSetField(feat,0,"data",featdata);

matrix.h

/*
 * Create a numeric array and initialize all its data elements to 0.
 *
 * Similar to mxCreateNumericMatrix, in a standalone application,
 * out-of-memory will mean a NULL pointer is returned.
 */
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag); //line 782
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_700(int ndim, const int *dims, mxClassID classid, mxComplexity flag);
int dims[2] = {buf->info().size , buf->availableTokens()};

Is signed, mxCreateNumericArray expects const size_t *, which is an unsigned numeric type. You either need to explicitly cast dims or define dims with the appropriate type.

Concretely, I'd edit the definition of dims in yaafe as follows:

size_t dims[2] = {static_cast<size_t>(buf->info().size) , static_cast<size_t>(buf->availableTokens())};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM