How to force MATLAB 2016a to use gcc-4.7.x instead of the one I have (gcc-5.4.1)?

1k views Asked by At

There are some posts about this for the older releases of MATLAB, but they don't seem to work for R2016a.

I'm trying to install MatConvNet on Ubuntu 16.04. When I run the vl_compilenn command as described here, it gives me a warning as follows:

Building with 'gcc'.
Warning: You are using gcc version '5.4.1'. The version of gcc is not supported. 
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.

I have already installed gcc-4.7 and g++-4.7 using apt-get install gcc-4.7 g++-4.7. How can I force MATLAB to use these versions and not the default ones?

2

There are 2 answers

0
Karel Lenc On

Few hints, not a complete tutorial how to do it. Probably the simplest would be to edit the MATLAB's Mex XML configuration file:

mex -setup C
cc = mex.getCompilerConfigurations('C', 'Selected')
edit(cc.MexOpt)

The mex setup usually creates a copy in your home folder (~/.matlab/<version>/mex_C_glnca64.xml), so you should be able to edit it without root.

There you probably need to change the section:

<GCC>
    <cmdReturns name="which gcc" />
</GCC>

which I guess searches for the location of the gcc command to your gcc version and assigns it to the $GCC variable. Plus you can change the version name in the header.

Additionally you need to do the same for the C++ language.

0
faken On

This works with R2016b:

  1. Install the required GCC version with apt install (gcc-4.9 and g++-4.9 in my case).

  2. Create a bin folder in your home, i.e. ~/bin.

  3. Create the following links with ln:

    • ln -s /usr/bin/gcc-4.9 ~/bin/gcc
    • ln -s /usr/bin/g++-4.9 ~/bin/g++
  4. If using CUDA, create a file called nvcc in the ~/bin folder, with the following contents (don't forget to make it executable: chmod +x ~/bin/nvcc):

Contents:

#!/bin/sh
exec /usr/lib/nvidia-cuda-toolkit/bin/nvcc -ccbin gcc-4.9 "$@"

If necessary replace /usr/lib/nvidia-cuda-toolkit/bin/nvcc with the correct location of the nvcc binary.

  1. Open MATLAB and follow the instructions for compiling MatConvNet.