Peter
Peter

Reputation: 387

Using previous version of gcc for mex in Matlab

I want to use gcc version 4.9 with Matlab. I have gcc-4.9 installed, but my attempts to use it with Matlab have been thwarted.

Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. 
The version currently supported with MEX is '4.9.x'. For a list of currently 
supported compilers see:

My Attempts:

1) mex -setup, and mex -setup C++

Does not display options to choose from, just shows

MEX configured to use 'gcc' for C language compilation.

And I don't know what to do with that.

2) https://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html

copyfile(fullfile(matlabroot,'extern','examples','refbook','timestwo.c'),'.','f') mex -v GCC='/usr/bin/gcc-4.7' timestwo.c

This does not apply to me, since I'm not trying to compile a single file.

3) Editing mexopts.sh both in "MatlabRoot/bin/" and ~/.matlab/R2016b

(restarted Matlab and got the same error)

Thanks in advance for the help!

Upvotes: 1

Views: 2950

Answers (1)

bdrhn9
bdrhn9

Reputation: 21

to change gcc and g++ version used in MATLAB (I'm using R2017b on Ubuntu 16.04), first of all, install gcc-4.9 and g++-4.9 using

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

to change version of gcc, run following command:

sudo gedit ~/.matlab/R2017b/mex_C_glnxa64.xml

and replace Location="$GCC" with Location="/usr/bin/gcc-4.9"

to change version of g++, run following command:

sudo gedit /usr/local/MATLAB/R2017b/bin/glnxa64/mexopts/g++_glnxa64.xml

and replace Location="$G++" with Location="/usr/bin/g++-4.9"

To verify that changes is done correctly, run following command in MATLAB Command Windows:

for gcc

myCCompiler = mex.getCompilerConfigurations('C','Selected')

for g++

myCCompiler = mex.getCompilerConfigurations('C++','Selected')

I hope, it helps.

Upvotes: 2

Related Questions