0
votes

Im trying to MEX piece of code with VS 2010 MATLAB 2012b and getting this error

c:\users\krzysztof\desktop\libocas_v096\libocas_v096\sparse_mat.h(27) : error C2371: 'mxArray' : redefinition; different basic types c:\program files\matlab\r2012b\extern\include\matrix.h(293) : see declaration of 'mxArray'

the code contains #include which includes matrix.h

another piece code includes sparse_mat.h which redefines matrix.h types e.g.

typedef struct {
  INDEX_TYPE_T *ir;
  INDEX_TYPE_T *jc;
  INDEX_TYPE_T m;
  INDEX_TYPE_T n;
  double *pr;
  NNZ_TYPE_T nzmax;
  int sparse;

} mxArray;

Any idea how to get rid of this error ?? GCC compiles this code.

Krzysztof

it complains about line 293. Below part from matrix.h with this line

#ifndef MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H
#define MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H

/* Copyright 2008 The MathWorks, Inc. */

/**
 * Published incomplete definition of mxArray
 */
typedef struct mxArray_tag mxArray; <--- line 293

#endif /* MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H */
2
Redefinition of structures isn't legal C. If GCC accepts the code, it's being pretty nice to you. Can you show both structure definitions?Carl Norum
it complains about line 293. Below part from matrix.h with this line ` #ifndef MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H #define MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H /* Copyright 2008 The MathWorks, Inc. / /* * Published incomplete definition of mxArray / typedef struct mxArray_tag mxArray; <--- line 293 #endif / MATHWORKS_MATRIX_MXARRAY_PUB_FWD_H */`user1944066
And why do you want to redefine it?Carl Norum
I'm not an author but just sent to author the email with the same question. Perhaps renaming should be enoughuser1944066
Could you try to rename your struct from mxArray? It's already defined. This should solve your issue.alekseyk

2 Answers

0
votes

Try to include header "mex.h" instead of "matrix.h".

0
votes

It seems that you aren't using the forward declaration correctly.

In

typedef struct {
  INDEX_TYPE_T *ir;
  INDEX_TYPE_T *jc;
  INDEX_TYPE_T m;
  INDEX_TYPE_T n;
  double *pr;
  NNZ_TYPE_T nzmax;
  int sparse;

} mxArray;

You're defining a new type called mxArray.

In

typedef struct mxArray_tag mxArray;

You are aliasing a type struct mxArray_tag to mxArray which collides witch the mxArray that you've already defined.

According to the comment in your code you're trying to declare an mxArray type by forward declaration. The correct way to do this for your code would be typedef mxArray mxArray_tag;. Or, more naturally, you could change the full type definition of your mxArray not to be an anonymous struct:

typedef struct _mxArray {
  INDEX_TYPE_T *ir;
  INDEX_TYPE_T *jc;
  INDEX_TYPE_T m;
  INDEX_TYPE_T n;
  double *pr;
  NNZ_TYPE_T nzmax;
  int sparse;

} mxArray;

and the forward declaration will be typedef struct _mxArray mxArray;.