NO

Author Topic: Integrating Pelles C and MATLAB for MEX file compilation  (Read 2931 times)

MichaelS

  • Guest
Integrating Pelles C and MATLAB for MEX file compilation
« on: September 02, 2014, 12:38:40 PM »
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:
Code: [Select]
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?

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Integrating Pelles C and MATLAB for MEX file compilation
« Reply #1 on: September 02, 2014, 01:49:17 PM »
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
Code: [Select]
#include <uchar.h>
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

MichaelS

  • Guest
Re: Integrating Pelles C and MATLAB for MEX file compilation
« Reply #2 on: September 02, 2014, 02:06:42 PM »
Thank you. This solved the type thing. Unfortunately, the #2114 warning still keeps popping up. The full source now is:
Code: [Select]
#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 ;
}

czerny

  • Guest
Re: Integrating Pelles C and MATLAB for MEX file compilation
« Reply #3 on: September 02, 2014, 02:17:26 PM »
You have neither used xi nor xr!

So, what dou you expect?

MichaelS

  • Guest
Re: Integrating Pelles C and MATLAB for MEX file compilation
« Reply #4 on: September 02, 2014, 03:08:28 PM »
That was incredibly stupid - I am very sorry. :( Commenting those non-used variables out, everything works like a charm now!