1

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?

Dr. Prasanna Date
  • 745
  • 1
  • 9
  • 29
  • Have you followed the steps [provided in the documentation](https://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html#bunsr9g)? – sco1 Mar 16 '17 at 10:46
  • Yes, but it either asks to change `$PATH` (which I'm not too keen on doing) or change the compiler for every `mex` call. Is it possible to change the gcc compiler supported by mex during matlab startup? – Dr. Prasanna Date Mar 16 '17 at 15:45

2 Answers2

0

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.

Karel Lenc
  • 820
  • 6
  • 11
0

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.
faken
  • 6,572
  • 4
  • 27
  • 28