How to get rid of error C2601?

8 ビュー (過去 30 日間)
Amit Kalhapure
Amit Kalhapure 2012 年 7 月 21 日
I'm encountering few errors listed below. This happens when I try to run cpp code in matlab using mex command.
mesh.cpp(463) : error C2061: syntax error : identifier 'mxArray'
mesh.cpp(466) : error C2601: 'main' : local function definitions are illegal
mesh.cpp(464): this line contains a '{' which has not yet been matched
I'm doing it this way
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int main(void)
{
<program content>
}
return;
}
Is this the right way of doing it?
Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 22 日
編集済み: Walter Roberson 2012 年 7 月 22 日
Are you trying to use lcc to compile your .cpp ? lcc is strictly a C compiler that cannot be used for C++ at all. lcc also only supports the 1989 C standard and not any C introduced after that.
Also, you should not have a routine named "main": MATLAB itself is effectively the main routine. "main" is used strictly to designate the first routine called for an application, and is not used to designate routines called as library functions.
The structure should look similar to
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
<program content>
return;
}
  2 件のコメント
Amit Kalhapure
Amit Kalhapure 2012 年 7 月 22 日
Walter: Yes it worked. Actually I had a main cpp file and other mutilple cpp files linked to it. I didn't know that we should run all the files with 'mex'. I was trying only main cpp file.
Thanks again.
Walter Roberson
Walter Roberson 2012 年 7 月 22 日
The problem with "const" went away when you removed the nested function?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by