Friday, January 14, 2011

Compiling C/C++ code from Matlab on Ubuntu Linux machine

It seems that there is much easier way of compiling and running C/C++ from your Matlab application, than the one I was trying before.

Reproducing the instructions on this blog here:

My version of gcc (4.4) is too high for Matlab R2009b (4.3), and Matlab chokes on it. The solution is as follows:

Install gcc-4.3:

sudo apt-get install gcc-4.3
sudo apt-get install g++-4.3

In matlab, run mex -setup and select the GCC compiler.(Choose option 2). Next, at the command line:

sudo gedit ~/.matlab/R2009b/

Replace all instances of CC=’gcc’ with CC=’gcc-4.3′, and al instances of CXX='g++' with CXX='g++-4.3'.
And restart Matlab !