Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
c program fails to compile with mex, while cpp program compiles fine

Subject: c program fails to compile with mex, while cpp program compiles fine

From: shome

Date: 1 Feb, 2013 10:10:08

Message: 1 of 4

Hi,
    I get the following error while compiling hello.c

>> mex hello.c
/usr/local/MATLAB/R2012a/bin/mex: 1: eval: -c: not found

    mex: compile of ' "hello.c"' failed.

Error using mex (line 206)
Unable to complete successfully.

Hello.c:

#include <math.h>
#include <matrix.h>
#include <mex.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mexPrintf("Hello World!\n");
}

if i rename hello.c to hello.cpp it compiles properly.

I guess matlab missing the c compiler.How do i fix the above problem.

Subject: c program fails to compile with mex, while cpp program compiles fine

From: someone

Date: 1 Feb, 2013 18:24:08

Message: 2 of 4

"shome" wrote in message <keg4a0$r58$1@newscl01ah.mathworks.com>...
> Hi,
> I get the following error while compiling hello.c
>
> >> mex hello.c
> /usr/local/MATLAB/R2012a/bin/mex: 1: eval: -c: not found
>
> mex: compile of ' "hello.c"' failed.
>
> Error using mex (line 206)
> Unable to complete successfully.
>
> Hello.c:
>
> #include <math.h>
> #include <matrix.h>
> #include <mex.h>
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
> mexPrintf("Hello World!\n");
> }
>
> if i rename hello.c to hello.cpp it compiles properly.
>
> I guess matlab missing the c compiler.How do i fix the above problem.

I may be completely off base here, but my understanding is that MATLAB doesn't "come" with a c compiler. It uses the c compiler you have (already) installed on your computer (with the "mex -setup" command).

Subject: c program fails to compile with mex, while cpp program compiles fine

From: James Tursa

Date: 1 Feb, 2013 18:53:08

Message: 3 of 4

"shome" wrote in message <keg4a0$r58$1@newscl01ah.mathworks.com>...
>
> Hello.c:
>
> #include <math.h>
> #include <matrix.h>
> #include <mex.h>

Try changing the above includes to:

#include <math.h>
#include "mex.h"


James Tursa

Subject: c program fails to compile with mex, while cpp program compiles fine

From: James Tursa

Date: 1 Feb, 2013 18:55:08

Message: 4 of 4

"someone" wrote in message <keh188$j0e$1@newscl01ah.mathworks.com>...
>
> I may be completely off base here, but my understanding is that MATLAB doesn't "come" with a c compiler. It uses the c compiler you have (already) installed on your computer (with the "mex -setup" command).

32-bit MATLAB typically ships with the lcc compiler (a C compiler). I don't think 64-bit MATLAB ships with any compiler (although I don't have 64-bit MATLAB myself to check this).

James Tursa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us