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:
Run C code in Matlab

Subject: Run C code in Matlab

From: Emma Robertson

Date: 3 Sep, 2011 15:01:25

Message: 1 of 7

Hi everyone,

I have never used/compiled C codes before and I am trying to run one in Matlab at the moment. Here's how I did it in a Mac OS:

Input "mex -setup" at the command line

I got the following options:

The options files available for mex are:

  1: /Applications/MATLAB_R2010aSV.app/bin/gccopts.sh :
      Template Options file for building gcc MEX-files
 
  2: /Applications/MATLAB_R2010aSV.app/bin/mexopts.sh :
      Template Options file for building MEX-files via the system ANSI compiler
 

  0: Exit with no changes

Enter the number of the compiler (0-2):
2

Overwrite /Users/username/.matlab/R2010a/mexopts.sh ([y]/n)?
y

Then I wrote the following in the command line
mex filename.c
and got
??? Error using ==> mex at 222
Unable to complete successfully.

I tried running it with option 1 but got the same error message. Any idea if this is a compiling error or if it is actually an error within the code. The code is very long and hence it is not a good idea to post it here. If anyone has the time to assist with this query I can email the code instead.

I appreciate any input thanks
Emma

Subject: Run C code in Matlab

From: Wayne King

Date: 3 Sep, 2011 17:33:28

Message: 2 of 7

"Emma Robertson" wrote in message <j3tfg5$l10$1@newscl01ah.mathworks.com>...
> Hi everyone,
>
> I have never used/compiled C codes before and I am trying to run one in Matlab at the moment. Here's how I did it in a Mac OS:
>
> Input "mex -setup" at the command line
>
> I got the following options:
>
> The options files available for mex are:
>
> 1: /Applications/MATLAB_R2010aSV.app/bin/gccopts.sh :
> Template Options file for building gcc MEX-files
>
> 2: /Applications/MATLAB_R2010aSV.app/bin/mexopts.sh :
> Template Options file for building MEX-files via the system ANSI compiler
>
>
> 0: Exit with no changes
>
> Enter the number of the compiler (0-2):
> 2
>
> Overwrite /Users/username/.matlab/R2010a/mexopts.sh ([y]/n)?
> y
>
> Then I wrote the following in the command line
> mex filename.c
> and got
> ??? Error using ==> mex at 222
> Unable to complete successfully.
>
> I tried running it with option 1 but got the same error message. Any idea if this is a compiling error or if it is actually an error within the code. The code is very long and hence it is not a good idea to post it here. If anyone has the time to assist with this query I can email the code instead.
>
> I appreciate any input thanks
> Emma

Hi Emma, Please share with us what you got before

??? Error using ==> mex at 222
Unable to complete successfully.

Weren't there other messages produced in the command window after you entered:

mex filename.c

Wayne

Subject: Run C code in Matlab

From: Emma Robertson

Date: 4 Sep, 2011 01:05:29

Message: 3 of 7

"Wayne King" <wmkingty@gmail.com> wrote in message <j3tod8$frl$1@newscl01ah.mathworks.com>...
> "Emma Robertson" wrote in message <j3tfg5$l10$1@newscl01ah.mathworks.com>...
> > Hi everyone,
> >
> > I have never used/compiled C codes before and I am trying to run one in Matlab at the moment. Here's how I did it in a Mac OS:
> >
> > Input "mex -setup" at the command line
> >
> > I got the following options:
> >
> > The options files available for mex are:
> >
> > 1: /Applications/MATLAB_R2010aSV.app/bin/gccopts.sh :
> > Template Options file for building gcc MEX-files
> >
> > 2: /Applications/MATLAB_R2010aSV.app/bin/mexopts.sh :
> > Template Options file for building MEX-files via the system ANSI compiler
> >
> >
> > 0: Exit with no changes
> >
> > Enter the number of the compiler (0-2):
> > 2
> >
> > Overwrite /Users/username/.matlab/R2010a/mexopts.sh ([y]/n)?
> > y
> >
> > Then I wrote the following in the command line
> > mex filename.c
> > and got
> > ??? Error using ==> mex at 222
> > Unable to complete successfully.
> >
> > I tried running it with option 1 but got the same error message. Any idea if this is a compiling error or if it is actually an error within the code. The code is very long and hence it is not a good idea to post it here. If anyone has the time to assist with this query I can email the code instead.
> >
> > I appreciate any input thanks
> > Emma
>
> Hi Emma, Please share with us what you got before
>
> ??? Error using ==> mex at 222
> Unable to complete successfully.
>
> Weren't there other messages produced in the command window after you entered:
>
> mex filename.c
>
> Wayne


Sure. I got this before the error message

/Applications/MATLAB_R2010aSV.app/bin/mex: line 306: gcc-4.0: command not found
/Applications/MATLAB_R2010aSV.app/bin/mex: line 1058: gcc-4.0: command not found

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

Thanks.

Subject: Run C code in Matlab

From: Christopher Creutzig

Date: 5 Sep, 2011 11:31:32

Message: 4 of 7

On 04.09.11 03:05, Emma Robertson wrote:

> Sure. I got this before the error message
>
> /Applications/MATLAB_R2010aSV.app/bin/mex: line 306: gcc-4.0: command not found
> /Applications/MATLAB_R2010aSV.app/bin/mex: line 1058: gcc-4.0: command not found
>
> mex: compile of ' "filename.c"' failed.

Please note that you need to install a C compiler first. The easiest way
is probably to download XCode from
http://developer.apple.com/xcode/index.php


Christopher

Subject: Run C code in Matlab

From: Emma Robertson

Date: 6 Sep, 2011 21:26:13

Message: 5 of 7

Hi

Thanks for the link.

I would need to upgrade my OS (to Lion) to download the Xcode you mentioned and I don't want to do that just yet. Is there any other compiler you would suggest?

Subject: Run C code in Matlab

From: Ron Daigle

Date: 7 Sep, 2011 00:03:07

Message: 6 of 7

"Emma Robertson" wrote in message <j4635l$mj$1@newscl01ah.mathworks.com>...
> Hi
>
> Thanks for the link.
>
> I would need to upgrade my OS (to Lion) to download the Xcode you mentioned and I don't want to do that just yet. Is there any other compiler you would suggest?

Emma,

The install disc that came with your Mac should have "developer tools" under optional installs. Installing this package should provide you with a workable version of GCC.

Subject: Run C code in Matlab

From: Christopher Creutzig

Date: 7 Sep, 2011 06:50:10

Message: 7 of 7

On 06.09.11 23:26, Emma Robertson wrote:

> I would need to upgrade my OS (to Lion) to download the Xcode you mentioned and I don't want to do that just yet. Is there any other compiler you would suggest?

Following that link, in the big white box, in the bottom right corner,
there is a link to XCode 3. If you don't have the developer tools DVD
any more or feel you bought your system so long ago that you should get
something slightly more up to date.


HTH,
Christopher

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