Mex compilation error in Windows

3 views (last 30 days)
Wajahat
Wajahat on 7 Sep 2012
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 Comments
Wajahat
Wajahat on 8 Sep 2012
Edited: Wajahat on 8 Sep 2012
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 on 9 Sep 2012
With "relevant part" I meant the relevant part only. Most of all it would be friendly to mention, which is the "line 32".

Sign in to comment.

Accepted Answer

Jan
Jan on 9 Sep 2012
Edited: Jan on 9 Sep 2012
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 Comments
Walter Roberson
Walter Roberson on 9 Sep 2012
Jan, variables are allowed mixed in with code in the C99 standard.
Jan
Jan on 9 Sep 2012
@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.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 8 Sep 2012
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 Comments
Wajahat
Wajahat on 8 Sep 2012
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 on 8 Sep 2012
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.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!