Hi!
I am working on a Win64 machine and use MATLAB R2012a as well as Pelles C Version 8.00.19 Release Candidate #6. Now, I want to integrate Pelles C into the mex environment of MATLAB, i.e. I want to use it as the compiler responsible for compiling mex files (C files, which interact with MATLAB like in-built functions). For this, I took inspiration from this submission: http://www.mathworks.com/matlabcentral/fileexchange/20877-mexopts-for-pelles-c
However, when I try to compile the mandelbrot.c example provided with above submission, I receive the following error message:
mex mandelbrot.c
C:\Program Files\MATLAB\R2012a\extern\include\tmwtypes.h(819): error #2048: Undeclared identifier 'char16_t' (did you mean 'char_T'?).
mandelbrot.c(12): warning #2114: Local 'xi' is not referenced.
mandelbrot.c(12): warning #2114: Local 'xr' is not referenced.
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'mandelbrot.c' failed.
Error using mex (line 206)
Unable to complete successfully.
Unfortunately, I cannot find what error #2048 refers to. Does anybody have experience with Pelles C and MEX file compilation?
include uchar.h as very first include file in your source.
The missing type 'char16_t' is defined there.
I.e. in the very first line of your file type
#include <uchar.h>
Thank you. This solved the type thing. Unfortunately, the #2114 warning still keeps popping up. The full source now is:
#include <uchar.h>
#include <math.h>
#include <complex.h>
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
/* function W = mandelbrot(iter, points, center, width);
* Complex arithmetic:
* z = z.^2 + z0
*/
{
double *xr,*xi,*W;
int np, width, iter, jj, ii, kk;
complex double C0, z;
double dz;
iter = ( int) mxGetScalar(prhs[0]);
np =( int) mxGetScalar(prhs[1]);
width = mxGetScalar(prhs[2]);
plhs[0] = mxCreateDoubleMatrix(np, np, mxREAL);
W = mxGetPr(plhs[0]);
dz= width / ((double) np - 1);
for (jj=0; jj<np; jj++) {
for (ii=0; ii<np; ii++) {
z=0;
/* current point in complex plane*/
C0 = -width/2 + dz*jj + I*(-width/2 + dz*ii);
/* iteration*/
for (kk=0; kk<iter; kk++) {
z = z*z + C0;
/* measure divergence speed*/
W[ii + jj*np] += (cabs(z)>=2);
}
}
}
return ;
}
You have neither used xi nor xr!
So, what dou you expect?
That was incredibly stupid - I am very sorry. :( Commenting those non-used variables out, everything works like a charm now!