why do I get an error message using template?

why do I get an error message using template?

Post by Deyue » Fri, 04 Jul 2003 01:01:36



I'm using CW7.0 on the Mac.  I got an error when I compiled the code
which copied from a windows C++ project.  The following are related
subroutines.  I can't send the whole one for it's too long.
Do you have any suggestion?  Thanks!
Dion

___________________________________
Link error:  undefined _cut_fp2unsigned' (code)
           Reference from _get_numeric <UL> (const mxArray_tag*,
unsigned long*)' in square_mexFunction.cp
___________________________________

//square_mexFunction.cp
..
..
// Load up an array (which may consist only of a single element) with
// the values from a matlab object.  Arguments:
// 1) The matlab object.
// 2) Where to put the values.  The array should be allocated
sufficiently
//    large so that all of the values in the matlab object can be
converted.
// These functions return 0 on error, or 1 if the operation succeded.
//
template <class FLOAT>
static int
_get_numeric(const mxArray *mat, FLOAT *arr) // float or double.
{
  int idx;
  int n_elements = _arraylen(mat); // Get the length.

  if (mxIsDouble(mat))          // Ordinary double precision matrix?
  {
    double *pr = mxGetPr(mat);  // Point to vector of double precision
values.

    for (idx = 0; idx < n_elements; ++idx) // Loop through all
elements.
      *arr++ = (FLOAT)*pr++;    // Convert and copy this element.
  }
  else                          // Don't know what this is.
    return 0;                   // Type conversion error.

  return 1;                     // No error.

Quote:}



void _wrap_GPCTR_Change_Parameter(int nlhs, mxArray **plhs, int nrhs,
const mxArray **prhs)
{
  if (nlhs > 1 ||
      nrhs != 4+1)
    mexErrMsgTxt("Wrong number of arguments to function
GPCTR_Change_Parameter");
  int _d[4] = { 1,1,1,1 };
  int _vec_n = 0;
  int _vidx;
  int _vec_sz;
  short *_arg_deviceNumber;
  unsigned long *_arg_gpCounterNumber;
  unsigned long *_arg_paramID;
  unsigned long *_arg_paramValue;
  short *_arg_retval;
  int _vecstride_deviceNumber = 1;
  int _vecstride_gpCounterNumber = 1;
  int _vecstride_paramID = 1;
  int _vecstride_paramValue = 1;
  if (!_check_input_vectorize(prhs[1], &_vec_n, _d, 0,
&_vecstride_deviceNumber))
    mexErrMsgTxt("Error in dimension of argument deviceNumber");
  if (mxIsInt16(prhs[1]) || mxIsUint16(prhs[1]))
    _arg_deviceNumber = (short *)mxGetData(prhs[1]);
  else
  {
    _arg_deviceNumber = MEM_ALLOC(short *, _arraylen(prhs[1]), sizeof
(short));
    if (!_get_numeric(prhs[1], _arg_deviceNumber))
      mexErrMsgTxt("Expecting numeric matrix for argument
deviceNumber");
  }

  if (!_check_input_vectorize(prhs[2], &_vec_n, _d, 0,
&_vecstride_gpCounterNumber))
    mexErrMsgTxt("Error in dimension of argument gpCounterNumber");
  if (mxIsInt32(prhs[2]) || mxIsUint32(prhs[2]))
    _arg_gpCounterNumber = (unsigned long *)mxGetData(prhs[2]);
  else
  {
    _arg_gpCounterNumber = MEM_ALLOC(unsigned long *,
_arraylen(prhs[2]), sizeof (unsigned long));
    if (!_get_numeric(prhs[2], _arg_gpCounterNumber))
      mexErrMsgTxt("Expecting numeric matrix for argument
gpCounterNumber");
  }

  if (!_check_input_vectorize(prhs[3], &_vec_n, _d, 0,
&_vecstride_paramID))
    mexErrMsgTxt("Error in dimension of argument paramID");
  if (mxIsInt32(prhs[3]) || mxIsUint32(prhs[3]))
    _arg_paramID = (unsigned long *)mxGetData(prhs[3]);
  else
  {
    _arg_paramID = MEM_ALLOC(unsigned long *, _arraylen(prhs[3]),
sizeof (unsigned long));
    if (!_get_numeric(prhs[3], _arg_paramID))
      mexErrMsgTxt("Expecting numeric matrix for argument paramID");
  }

  if (!_check_input_vectorize(prhs[4], &_vec_n, _d, 0,
&_vecstride_paramValue))
    mexErrMsgTxt("Error in dimension of argument paramValue");
  if (mxIsInt32(prhs[4]) || mxIsUint32(prhs[4]))
    _arg_paramValue = (unsigned long *)mxGetData(prhs[4]);
  else
  {
    _arg_paramValue = MEM_ALLOC(unsigned long *, _arraylen(prhs[4]),
sizeof (unsigned long));
    if (!_get_numeric(prhs[4], _arg_paramValue))
      mexErrMsgTxt("Expecting numeric matrix for argument
paramValue");
  }

  {
    int _ds[] = { _d[0] , _d[1] , _d[2] , _d[3]  };
    plhs[0] = mxCreateNumericArray(max((0 + _vec_n), 2), _ds,
mxDOUBLE_CLASS, mxREAL);
    _arg_retval = MEM_ALLOC(short *, _arraylen(plhs[0]), sizeof
(short));
  }
  _vec_sz = _d[0]*_d[1]*_d[2]*_d[3];
  for (_vidx = 0; _vidx < _vec_sz; ++_vidx) {
    _arg_retval[_vidx] = (short)
      GPCTR_Change_Parameter(_arg_deviceNumber[_vecstride_deviceNumber*_vidx],
_arg_gpCounterNumber[_vecstride_gpCounterNumber*_vidx],
_arg_paramID[_vecstride_paramID*_vidx],
_arg_paramValue[_vecstride_paramValue*_vidx]);
  }
  {
    int _fidx;
    double *d_ptr = mxGetPr(plhs[0]);
    for (_fidx = 0; _fidx < _arraylen(plhs[0]); ++_fidx)
      *d_ptr++ = (double)*_arg_retval++;
  }

Quote:}



 
 
 

why do I get an error message using template?

Post by MW Ro » Wed, 09 Jul 2003 05:47:12




Quote:>I'm using CW7.0 on the Mac.  I got an error when I compiled the code
>which copied from a windows C++ project.  The following are related
>subroutines.  I can't send the whole one for it's too long.
>Do you have any suggestion?  Thanks!
>___________________________________
>Link error:  undefined _cut_fp2unsigned' (code)
>           Reference from _get_numeric <UL> (const mxArray_tag*,
>unsigned long*)' in square_mexFunction.cp
>___________________________________

Linker errors for undefined items, are where you don't have the function
defined.  For example if you have mxGetPr in a header file it will
compile but if you have this function in a C source file or forgot to
add that file to your project  (or that library to the project) you will
get a linker undefined error.

Check to be sure you have the file in a C++ file.  It is easy to have
force C++ enabled in one and not in another and get these type of
undefined linker errors.

Bottome line is that the actual code  is missing or misnamed for _cut_

Ron

Quote:

>//square_mexFunction.cp
>..
>..
>// Load up an array (which may consist only of a single element) with
>// the values from a matlab object.  Arguments:
>// 1) The matlab object.
>// 2) Where to put the values.  The array should be allocated
>sufficiently
>//    large so that all of the values in the matlab object can be
>converted.
>// These functions return 0 on error, or 1 if the operation succeded.
>//
>template <class FLOAT>
>static int
>_get_numeric(const mxArray *mat, FLOAT *arr) // float or double.
>{
>  int idx;
>  int n_elements = _arraylen(mat); // Get the length.

>  if (mxIsDouble(mat))              // Ordinary double precision matrix?
>  {
>    double *pr = mxGetPr(mat);      // Point to vector of double precision
>values.

>    for (idx = 0; idx < n_elements; ++idx) // Loop through all
>elements.
>      *arr++ = (FLOAT)*pr++;        // Convert and copy this element.
>  }
>  else                              // Don't know what this is.
>    return 0;                       // Type conversion error.

>  return 1;                 // No error.
>}

--
           Metrowerks has moved, our new address is now
                     7700 West Parmer Lane
                       Austin, TX 78729
        Sales and Support 512-996-5300   800-377-5416