在Matlab中将.cc文件编译为mex时出错

时间:2014-01-13 08:25:22

标签: matlab compilation mex cc

我正在尝试将.cc文件编译为mex,我在Matlab中使用mex filename命令。我的编译器是[1] Lcc-win32 C 2.4.1 in C:\ PROGRA~1 \ MATLAB \ R2012b \ sys \ lcc。

但是,有一些错误:

 lcc preprocessor error: learn.cc:5 Could not find include file <sys/time.h> 
Error learn.cc: 70  illegal statement termination 
Error learn.cc: 70  skipping `int' 
Error learn.cc: 70  undeclared identifier `alen' 
Error learn.cc: 71  illegal statement termination 
Error learn.cc: 71  skipping `int' 
Error learn.cc: 71  undeclared identifier `blen' 
Error learn.cc: 87  invalid struct field declarations 
Error learn.cc: 87  syntax error; found `collapsed' expecting `}' 
Error learn.cc: 87  skipping `collapsed' `*' `x' 
Error learn.cc: 93  unrecognized declaration 
Warning learn.cc: 93  empty declaration 
Error learn.cc: 97  undefined size for `incomplete struct timeval defined at learn.cc 97 tp' 
Error learn.cc: 99  unknown field `tv_usec' of `incomplete struct timeval defined at learn.cc 97' 
Error learn.cc: 102  syntax error; found `double' expecting `;' 
Error learn.cc: 103  syntax error; found `double' expecting `;' 
Error learn.cc: 106  missing parameter type 
Error learn.cc: 106  syntax error; found `X' expecting `)' 
Error learn.cc: 106  skipping `X' `,' 
Error learn.cc: 106  syntax error; found `double' expecting `{' 
Error learn.cc: 106  missing identifier 
Error learn.cc: 106  too many errors 

我猜第一个错误的原因是sys文件夹中没有time.h文件。而是有timeb.h文件。但我不知道出现以下错误的原因。

以下是一些相关代码:

line 70     int alen = **((int **)a);
line 71     int blen = **((int **)b);
line 86-93  struct data {
  collapsed *x;
  int num;
  int numblocks;
  int *blocksizes;
  float *regmult;
  float *learnmult;
};
line 96-100 void seed_time() {
 struct timeval tp;
 check(gettimeofday(&tp, NULL) == 0);
 srand48((long)tp.tv_usec);
}
line 102 static inline double min(double x, double y) { return (x <= y ? x : y); }
line 103 static inline double max(double x, double y) { return (x <= y ? y : x); }

任何人都可以给我一个提示吗?

1 个答案:

答案 0 :(得分:0)

据我所知,第70,71行没有任何问题。是a,b整数双数组声明和分配类似于:

int ** a = malloc(4 * sizeof(int*) ); for (int var = 0; var < 4; ++var) { a[var] = malloc(3*sizeof(int)); }

您确定sys / time.h.h文件可以替换sys / time.h文件吗?你有没有尝试过? sys / time.h看起来像一个漂亮的linux / unix特定文件。你确定sys /文件夹引用你的matlab sys目录(C:\ PROGRA~1 \ MATLAB \ R2012b \ sys \ lcc)吗?

通常,看起来您正在尝试在Windows机器上编译linux .mex文件。例如gettimeofday是一个linux纯调用(根据这个答案): Equivalent of gettimeday() for Windows