MATLAB Answers


mex can't find gcc in path

Asked by Robert
on 22 Aug 2011

Matlab-mex can't find my C compiler, even though it appears to be using the correct command. Observe:

In Matlab: >> mex foo.c /Applications/ line 305: gcc-4.2: command not found /Applications/ line 1041: gcc-4.2: command not found

In Terminal: $which gcc-4.2 /Developer/usr/bin/gcc-4.2

Any idea how to get mex to find the compiler? I'm using Mac OS Lion and 2011a.


Log in to comment.

3 Answers

Answer by Robert
on 22 Aug 2011
 Accepted Answer

I figured it out. All I had to do is run: sudo ln -s /Developer/usr/bin/gcc-4.2 /usr/bin/gcc-4.2

The problem was that /Developer/usr/bin/ is in my Terminal path, but apparently not in mex's path when looking for a compiler.


Log in to comment.

Answer by Nathan
on 22 Apr 2012

For anyone (like me) that the above fix did not work for, download the patch discussed here:

And make the modification to described here:

Those two did the trick for me.


Log in to comment.

Answer by Shahab
on 31 May 2012

Thank you Nathan :) it is exciting.


Log in to comment.

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!