Mex compilation error in Windows

조회 수: 3 (최근 30일)
Wajahat
Wajahat 2012년 9월 7일
Hi
I have a piece of code which compiles without any error or warning in Linux with GCC but in windows with Visual C++2010 as the compiler, give a list of following errors. Any idea what is the reason:
bttc_m.c(32) : error C2143: syntax error : missing ';' before 'const'
bttc_m.c(33) : error C2065: 'dim' : undeclared identifier
bttc_m.c(33) : error C2109: subscript requires array or pointer type
bttc_m.c(33) : error C2065: 'dim' : undeclared identifier
bttc_m.c(33) : error C2109: subscript requires array or pointer type
bttc_m.c(35) : error C2065: 'dim' : undeclared identifier
bttc_m.c(35) : error C2109: subscript requires array or pointer type
bttc_m.c(43) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(73) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(74) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(75) : error C2065: 'i' : undeclared identifier
bttc_m.c(75) : error C2065: 'i' : undeclared identifier
bttc_m.c(75) : error C2065: 'i' : undeclared identifier
bttc_m.c(76) : error C2065: 'j' : undeclared identifier
bttc_m.c(76) : error C2065: 'j' : undeclared identifier
bttc_m.c(76) : error C2065: 'j' : undeclared identifier
bttc_m.c(77) : error C2065: 'dat' : undeclared identifier
bttc_m.c(77) : error C2065: 'j' : undeclared identifier
bttc_m.c(77) : error C2065: 'i' : undeclared identifier
bttc_m.c(77) : error C2109: subscript requires array or pointer type
bttc_m.c(77) : error C2065: 'i' : undeclared identifier
bttc_m.c(77) : error C2065: 'j' : undeclared identifier
bttc_m.c(116) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(117) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(119) : error C2065: 'dims' : undeclared identifier
bttc_m.c(119) : error C2109: subscript requires array or pointer type
bttc_m.c(120) : error C2065: 'dims' : undeclared identifier
bttc_m.c(120) : error C2109: subscript requires array or pointer type
bttc_m.c(121) : error C2065: 'dims' : undeclared identifier
bttc_m.c(121) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'int'
bttc_m.c(121) : warning C4024: 'mxCreateNumericArray_700' : different types for formal and actual parameter 2
bttc_m.c(122) : error C2065: 'dat' : undeclared identifier
bttc_m.c(122) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *'
bttc_m.c(124) : error C2065: 'dat' : undeclared identifier
bttc_m.c(124) : error C2065: 'dims' : undeclared identifier
bttc_m.c(124) : error C2109: subscript requires array or pointer type
bttc_m.c(125) : error C2065: 'dat' : undeclared identifier
bttc_m.c(125) : error C2065: 'dims' : undeclared identifier
bttc_m.c(125) : error C2109: subscript requires array or pointer type
bttc_m.c(126) : error C2065: 'dat' : undeclared identifier
bttc_m.c(126) : error C2065: 'dims' : undeclared identifier
bttc_m.c(126) : error C2109: subscript requires array or pointer type
bttc_m.c(129) : error C2065: 'dims' : undeclared identifier
bttc_m.c(129) : error C2109: subscript requires array or pointer type
bttc_m.c(130) : error C2065: 'dims' : undeclared identifier
bttc_m.c(130) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'int'
bttc_m.c(130) : warning C4024: 'mxCreateNumericArray_700' : different types for formal and actual parameter 2
bttc_m.c(131) : error C2065: 'dat' : undeclared identifier
bttc_m.c(131) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *'
bttc_m.c(134) : error C2065: 'dat' : undeclared identifier
bttc_m.c(134) : error C2065: 'dims' : undeclared identifier
bttc_m.c(134) : error C2109: subscript requires array or pointer type
bttc_m.c(176) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(177) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(179) : error C2065: 'dims' : undeclared identifier
bttc_m.c(179) : error C2109: subscript requires array or pointer type
bttc_m.c(180) : error C2065: 'dims' : undeclared identifier
bttc_m.c(180) : error C2109: subscript requires array or pointer type
bttc_m.c(181) : error C2065: 'dims' : undeclared identifier
bttc_m.c(181) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'int'
bttc_m.c(181) : warning C4024: 'mxCreateNumericArray_700' : different types for formal and actual parameter 2
bttc_m.c(182) : error C2065: 'dat' : undeclared identifier
bttc_m.c(182) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *'
bttc_m.c(184) : error C2065: 'dat' : undeclared identifier
bttc_m.c(184) : error C2065: 'dims' : undeclared identifier
bttc_m.c(184) : error C2109: subscript requires array or pointer type
bttc_m.c(185) : error C2065: 'dat' : undeclared identifier
bttc_m.c(185) : error C2065: 'dims' : undeclared identifier
bttc_m.c(185) : error C2109: subscript requires array or pointer type
bttc_m.c(186) : error C2065: 'dat' : undeclared identifier
bttc_m.c(186) : error C2065: 'dims' : undeclared identifier
bttc_m.c(186) : error C2109: subscript requires array or pointer type
bttc_m.c(189) : error C2065: 'dims' : undeclared identifier
bttc_m.c(189) : error C2109: subscript requires array or pointer type
bttc_m.c(190) : error C2065: 'dims' : undeclared identifier
bttc_m.c(190) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'int'
bttc_m.c(190) : warning C4024: 'mxCreateNumericArray_700' : different types for formal and actual parameter 2
bttc_m.c(191) : error C2065: 'dat' : undeclared identifier
bttc_m.c(191) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *'
bttc_m.c(194) : error C2065: 'dat' : undeclared identifier
bttc_m.c(194) : error C2065: 'dims' : undeclared identifier
bttc_m.c(194) : error C2109: subscript requires array or pointer type
bttc_m.c(197) : error C2065: 'dims' : undeclared identifier
bttc_m.c(197) : error C2109: subscript requires array or pointer type
bttc_m.c(198) : error C2065: 'dims' : undeclared identifier
bttc_m.c(198) : error C2109: subscript requires array or pointer type
bttc_m.c(199) : error C2065: 'dims' : undeclared identifier
bttc_m.c(199) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'int'
bttc_m.c(199) : warning C4024: 'mxCreateNumericArray_700' : different types for formal and actual parameter 2
bttc_m.c(200) : error C2143: syntax error : missing ';' before 'type'
bttc_m.c(201) : error C2065: 'tr' : undeclared identifier
bttc_m.c(201) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *'
bttc_m.c(205) : error C2065: 'tr' : undeclared identifier
bttc_m.c(205) : error C2109: subscript requires array or pointer type
bttc_m.c(221) : error C2065: 't1' : undeclared identifier
bttc_m.c(221) : error C2065: 't0' : undeclared identifier
bttc_m.c(221) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
bttc_m.c(222) : error C2065: 't1' : undeclared identifier
C:\PROGRA~2\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'bttc_m.c' failed.
Error using mex (line 206)
Unable to complete successfully.
  댓글 수: 4
Wajahat
Wajahat 2012년 9월 8일
편집: Wajahat 2012년 9월 8일
You can even try to compile the whole package yourself if you download it from: https://github.com/bobbens/libbttc/zipball/bttc-1.0
unzip into a folder, change Matlab's working directory to that folder and type:
mex bttc_m.c bttc.c
Jan
Jan 2012년 9월 9일
With "relevant part" I meant the relevant part only. Most of all it would be friendly to mention, which is the "line 32".

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 9월 9일
편집: Jan 2012년 9월 9일
If you configure your compiler to compile C code conform to the C89-standards, the variables must be declared before the code. The declaration inside the code is a C++ or C99 style [EDITED, added C99, thanks Walter]:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
int *faces, n;
double *img, threshold;
int size;
const mwSize *dim;
...
/* Checks. */
dim = mxGetDimensions(prhs[0]);
MSVC does accept the C++ and C99-style comments started by // in opposite to GCC, which is configured to the C89-style by Matlab. It seems like MSVC is stricter as GCC for the rule "declarations before statements". To test this, you can rename your file to "bttc_m.cpp".
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 9월 9일
Jan, variables are allowed mixed in with code in the C99 standard.
Jan
Jan 2012년 9월 9일
@Walter: Thanks, I've added this detail. MSVC2010 replies TRUE for some comparisons with NaN's, what clearly breaks IEEE754. I'm afraid, that standards from 1989 and 1999 are meaningless, when the manufacturers of compilers do not care about them in 2012. Frustrating.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 9월 8일
Unlike MATLAB, in c you need to declare variables. It looks like it's telling you that you didn't declare them as int, char, etc.
  댓글 수: 2
Wajahat
Wajahat 2012년 9월 8일
Yeah, I know and all the variables are defined correctly and this is the reason that the same code compiles perfectly in Linux with matlab configured with gcc.
Even when I configure Matlab in Windows with Mingw (gcc) using Gnumex, it still works. I am just curious what is wrong that it does not compile with VC++ Visual Studio 2010 configured in Matlab.
Whereas I can compile other files, e.g. sample files in matlab with VC++.
Image Analyst
Image Analyst 2012년 9월 8일
You paid a lot for the compiler (which includes support for it), so I'd call them and get your money's worth. They'll help you figure it out.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by