For the installation in ubuntu, one can follow the instructions in the following link:
https://help.ubuntu.com/community/MATLAB
However, I could not mex a
c code in ubuntu.
The
c code is
mtimesx.c, and I use the following command:
mex -v -DDEFINEUNIX -largeArrayDims mtimesx.c -lmwblas -lmwlapack
It gives the following error:
Warning: You are using gcc version "4.8.2". The version
currently supported with MEX is "4.7.x".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
-> gcc -c -I/usr/local/MATLAB/R2014b/extern/include -I/usr/local/MATLAB/R2014b/simulink/include -DMATLAB_MEX_FILE -std=c99 -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DDEFINEUNIX -O -DNDEBUG "mtimesx.c"
mtimesx.c: In function ‘mexFunction’:
mtimesx.c:592:10: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]
ans = mexGetVariablePtr("caller","OMP_SET_NUM_THREADS");
^
-> gcc -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2014b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "mtimesx.mexa64" mtimesx.o -lmwblas -lmwlapack -Wl,-rpath-link,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
mex: link of ' "mtimesx.mexa64"' failed.
Unable to complete successfully.
The solution to this is to change the gcc version for mex. However, in this matlab 2014b, it does not allow you to choose gcc compiler in
mex setup function. The way to do it is the following:
- install gcc-4.7 and g++-4.7 in ubuntu through synaptic package manager.
- then find the file "mexopts.sh" in folder .\home\.matlab\R2014b and open the file. you may need to change the permission of the file in order to modify it.
- find CC='gcc' in "mexopts.sh", and change it to CC='gcc-4.7'
- find CXX='g++' in "mexopts.sh", and change it to CXX='g++-4.7'
- save the file.
Then mex functions well in matlab.
Please leave a comment if you find it is useful.
-Shun