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



我正在尝试将.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); }

谁能给我一个提示?

据我所知,第 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纯调用(根据这个答案):相当于 Windows 的 gettimeday()

相关内容

  • 没有找到相关文章

最新更新