Mex compilation error in Windows
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 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".
Réponse acceptée
Jan
le 9 Sep 2012
Modifié(e) : Jan
le 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 commentaires
Jan
le 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.
Plus de réponses (1)
Image Analyst
le 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 commentaires
Image Analyst
le 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.
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!