mex compile error caused by different position of mexPrintf()
古いコメントを表示
I have got this code from website, saved it as hello.c and set up mex using MSVC 2010 compiler. It gives me compile errors. Such as illegal use of mxArray and undefined variables error.
#include <matrix.h>
#include <math.h>
#include <mex.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
mexPrintf("hello, world!\n");
//declare variables
mxArray *a_in_m;
mxArray *b_in_m;
mxArray *c_out_m;
mxArray *d_out_m;
const mwSize *dims;
double *a, *b, *c, *d;
int dimx, dimy, numdims;
//associate inputs
a_in_m = mxDuplicateArray(prhs[0]);
b_in_m = mxDuplicateArray(prhs[1]);
//figure out dimensions
dims = mxGetDimensions(prhs[0]);
numdims = mxGetNumberOfDimensions(prhs[0]);
dimy = (int)dims[0]; dimx = (int)dims[1];
//associate outputs
c_out_m = plhs[0] = mxCreateDoubleMatrix(dimy, dimx, mxREAL);
d_out_m = plhs[1] = mxCreateDoubleMatrix(dimy, dimx, mxREAL);
}
However, when I put the mexPrintf sentence in after the declaration part. The errors are gone.
#include <matrix.h>
#include <math.h>
#include <mex.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
//declare variables
mxArray *a_in_m;
mxArray *b_in_m;
mxArray *c_out_m;
mxArray *d_out_m;
const mwSize *dims;
double *a, *b, *c, *d;
int dimx, dimy, numdims;
mexPrintf("hello, world!\n");
//associate inputs
a_in_m = mxDuplicateArray(prhs[0]);
b_in_m = mxDuplicateArray(prhs[1]);
//figure out dimensions
dims = mxGetDimensions(prhs[0]);
numdims = mxGetNumberOfDimensions(prhs[0]);
dimy = (int)dims[0]; dimx = (int)dims[1];
//associate outputs
c_out_m = plhs[0] = mxCreateDoubleMatrix(dimy, dimx, mxREAL);
d_out_m = plhs[1] = mxCreateDoubleMatrix(dimy, dimx, mxREAL);
}
Could anyone explain why this happens? Thanks!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Write 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!