0

我正在尝试将 .cc 文件编译为 mex,并且我在 Matlab 中使用 mex 文件名命令。我的编译器是 [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); }

谁能给我一个提示?

4

1 回答 1

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 文件可以替换为 sys/timeb.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

于 2014-01-13T10:09:54.587 回答