Friday, 11 November 2011

Setting up Matlab mex compilation in Ubuntu

NOTE: This post was updated on January 16, 2012.

Recently I have been trying to compile some Matlab mex-files from the excellent Machine Vision Toolbox by Peter Corke. When I first tried to compile, I got the following warning:

Warning: You are using gcc version "4.6.1-9ubuntu3)".  The version
         currently supported with MEX is "4.3.4".

I tried several ways of "downgrading" gcc, but as it turns out, the newer version of gcc on Ubuntu 11.10 is backwards compatible and works fine. The message above is simply a warning, not an error, and there is no need to change gcc to an older version. However, my real problem was this: I got errors of the type

error: expected expression before ‘/’ token

I had no idea why this error was popping up, until I read a post on similar issues on xcorr. It turns out that C++ style "//" comments are not allowed in the standard mex configuration that is set when you run "mex -setup". To avoid the error, open the file (mine is located in ~/.matlab/R2011b/, and replace all occurences of "-ansi" with "-std=c99".


Vito said...

What do you mean "the newer version of gcc on Ubuntu 11.10 is backwards compatible and works fine"? Did you find a way to avoid the installation of an older version on a separate partition? Thanks!

Anonymous said...

I encounter exactly the same problem and am looking for a solution! Your post is a bit confusing and seems to be providing some information while says nothing really for solution! Could you please verify how it can be solved! Thank you!

Martin H. Skjelvareid said...

I'm terribly sorry, but I didn't see the above comments until now. I've updated the post so that it is (I hope) a bit clearer. The very short version:
- Ignore warnings about old GCC version
- Replace "-ansi" with "-std=c99" in

Thank you for commenting! :)

Anonymous said...

Unfortunately didn't solve my problem! :(

Anonymous said...

Helped me right away!
Many thanks!

Sagar said...

Thanks a ton for this. It worked like a charm!

Post a Comment