Setup MEX compiler for R2014a for Linux

Ubuntu 14.04 comes with GCC 4.8. Matlab 2014a only supports up to GCC 4.7. When I use 2013a I can set the mexopts.sh script to use GCC-4.7 by doing the following
1) In matlab, type mex -setup and press 1 to copy mexopts.sh to ~/.matlab/R2013b/mexopts.sh
2) From the terminal, edit the file ~/.matlab/R2013b/mexopts.sh so that CC=’gcc’ change to –> CC=’gcc-4.7′ CCX=’g++’ change to –> CCX=’g++-4.7′
In 2014a the mexopts.sh file does not exist anymore. When I type mex -setup I get the following error:
>> mex -setup C++
Error using mex
No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014a/glnxa64.
I know GCC 4.7 is installed because it works for R2013b but how do I set compiler in 2014a?

1 commentaire

Awais Ashfaq
Awais Ashfaq le 22 Fév 2016
Hi, I have a similar problem. Where should I copy the mexopts.sh? I can't find any folder MATLABversion? Cheers

Connectez-vous pour commenter.

 Réponse acceptée

Mukul Rao
Mukul Rao le 14 Juil 2014
Hi,
Beginning version R2014a, MATLAB automatically configures the mex pseudo compiler to use a supported compiler (such as gcc 4.7x ) on your machine. This leaves the use of the command “mex –setup” redundant unless you would like to use a supported compiler that is different from the default selection, or force MATLAB to use an unsupported compiler.
Did you try mexing a simple mex file like “timestwo.c” to check if the “mex file_name.x” command works on R2014a?
>> copyfile(fullfile(matlabroot,'extern','examples','refbook',...
'timestwo.c'), '.', 'f');
>> mex timestwo.c
Make sure you have write permission in your current working directory

6 commentaires

Nathan
Nathan le 16 Juil 2014
Thanks for the response Mukul. I tried your suggestion and it did not work. The only way I found to fix the problem which to change the symbolic link for gcc from 4.8 to 4.7 outside of Matlab. This means any time I call gcc outside of Matlab it will point to gcc-4.7 rather than 4.8.
I have not figured out how to choose the complier inside Matlab without changing the symbolic link.
The problem is that if Matlab finds a compiler with a higher version, it starts using it - after emitting a warning. For example when I used mex -setup, I had gcc 4.8 on my system. I got the warning:
Warning: You are using gcc version '4.8.1'. The version of gcc is not supported. The version currently supported with MEX is
'4.7.x'.
So I installed gcc 4.7 and changed mexopts.sh. But that doesn't change anything. So how do I tell matlab to downgrade to a version that is now available?
Note: I don't want to point gcc and g++ in the usr/bin directory to 4.7 as other applications are also using the higher version.
Please advise.
Sergey Demyanov
Sergey Demyanov le 11 Nov 2014
How did you change your mexopts.h? You need to copy mexopts.h from MatlabRoot"/bin/mexopts.sh to ~/.matlab/"MatlabVersion", and change 1) CC='gcc' on CC='gcc-4.7', 2) CXX='g++' on CXX='g++-4.7'. because 'gcc' and 'g++' are still aliases for higher versions of gcc and g++. You don't need to run mex -setup after that.
Joao Henriques
Joao Henriques le 17 Nov 2014
Thank you Sergey, copying mexopts to the home folder and changing the GCC version there was exactly what I needed! If you wrote that as an answer I'd upvote it.
Awais Ashfaq
Awais Ashfaq le 22 Fév 2016
Hi, I have a similar problem. Where should I copy the mexopts.sh? I can't find any folder MATLABversion? Cheers
wided hechkel
wided hechkel le 11 Fév 2017
Hello,
Should i delete the mexopts.sh from MatlabRoot"/bin/mexopts.sh after changing and copying it to ~/.matlab/"MatlabVersion" ?

Connectez-vous pour commenter.

Plus de réponses (3)

JIAWEI WU
JIAWEI WU le 26 Jan 2015

2 votes

Thanks Sergey, I copied the file mexopts.h as you said, it works here. it cost me one night to fix it, until now, finally, it has been solved. you are so great!
Dave
Dave le 14 Avr 2017
Modifié(e) : Dave le 16 Avr 2017
My solution for R2017a on Ubuntu 16.04.
First install the version of GCC Matlab expects:
sudo apt-get install gcc-4.9
Then edit the configuration file to point to this:
cd ~/.matlab/R2017a
sudo chmod 777 mex_C_glnxa64.xml
gedit mex_C_glnxa64.xml
Within that xml file, replace:
Location="$gcc"
with
Location="/usr/bin/gcc-4.9"
Save file and Matlab should no longer produce wrong version warnings.
wided hechkel
wided hechkel le 11 Fév 2017

0 votes

Hello,
Should i delete the mexopts.sh from MatlabRoot"/bin/mexopts.sh after changing and copying it to ~/.matlab/"MatlabVersion" ?

1 commentaire

jie Chang
jie Chang le 12 Mar 2017
Hello,could you tell me where the direction ~/.matlab/“MatlabVersion”is? thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Compiler SDK dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by