0

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 */
4

2 回答 2

0

尝试包含 header"mex.h"而不是"matrix.h".

于 2013-01-04T09:52:18.370 回答
0

看来您没有forward declaration正确使用。

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;

您正在定义一个名为mxArray.

typedef struct mxArray_tag mxArray;

您正在为一个与您已经定义的类型发生冲突的类型struct mxArray_tag起别名。mxArraymxArray

根据您的代码中的注释,您正在尝试mxArray通过前向声明来声明类型。为您的代码执行此操作的正确方法是typedef mxArray mxArray_tag;. 或者,更自然地,您可以将您的完整类型定义更改mxArray为非匿名结构:

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;

并且前向声明将是typedef struct _mxArray mxArray;.

于 2013-01-04T10:08:40.950 回答