2014-01-13 115 views
0

我試圖編譯.cc文件到mex,並且我在Matlab中使用了mex filename命令。我的編譯器是C:\ PROGRA〜1 \ MATLAB \ R2012b \ sys \ lcc中的[1] Lcc-win32 C 2.4.1。在Matlab中將.cc文件編譯爲mex時出現錯誤

但是,也存在一些誤區:

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); } 

誰能給我一個提示?

+0

'sys/time.h'在一個非可移植的Unix/Linux頭文件中,Windows上不可用...可能其餘的錯誤是由該頭文件中未定義的類型引起的。 – Amro

+0

你可以在Windows上使用Cygwin/MinGW GCC編譯器,但這是一個完全不同的故事:) – Amro

回答

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系統目錄(C:\ PROGRA〜1 \ MATLAB \ R2012b \ sys \ lcc)嗎?

一般來說,它看起來像你試圖在Windows機器上編譯一個linux .mex文件。例如,gettimeofday是一個純粹的linux調用(根據這個答案): Equivalent of gettimeday() for Windows