I'm using Ubuntu 18.04.4 LTS, and I'm trying to compile a MATLAB-based program (SPM12), following their online instructions, and I believe I'm running into a problem of having a GCC version that is 'too new'. When I reach a step in the process where my command is make && make install, I'm getting the following error message:

Warning: You are using gcc version '7.5.0'. The version of gcc is not supported. The version currently supported with MEX is '6.3.x'. For a list of currently supported compilers see: https://www.mathworks.com/support/compilers/current_release.
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status

Makefile:247: recipe for target 'spm_sample_vol.mexa64' failed
make: *** [spm_sample_vol.mexa64] Error 255

Any advice would be greatly appreciated! I'm no expert, so if you could offer specific commands to follow I'd really appreciate that. Ben


2 Answers 2


First of all try to find a Ubuntu release that was out after the release of the required version of GCC. You can find the release history of GCC on GCC Releases - GNU Project - Free Software Foundation (FSF) and that of Ubuntu on Ubuntu version history - Wikipedia.

GCC 6.3 was released on December 21, 2016 and the closest Ubuntu release was Ubuntu 17.04 (Zesty Zapus) which was released in April 2017. You can use the archives of Zesty to install that. But since Zesty reached end of life way back in January 2018, therefore, its archives have been moved to Old Releases. To install GCC 6.3 from its repository:

  1. Add the repository of Zesty and disable the Universe repository of Bionic since it contains 6.4 as well as 6.5 which might get installed while trying to install 6.3.

    echo "deb http://old-releases.ubuntu.com/ubuntu zesty main" | sudo tee /etc/apt/sources.list.d/zesty.list
    sudo apt-add-repository -r universe
  2. Update the available package information and install GCC 6.3.

    sudo apt update
    sudo apt install gcc-6
  3. Add GCC 6 as an alternative for GCC.

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 1
  4. Check the GCC version using gcc -v. You should get the output like:

    Using built-in specs.
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2) 
  5. Once you're done with "making", you can remove the installed GCC 6.3 and the repository information of Zesty. And re-enable Universe repository of Bionic.

    sudo apt purge gcc-6
    sudo apt autoremove --purge
    sudo rm /etc/apt/sources.list.d/zesty.list
    sudo apt-add-repository universe
  6. Fix the symlink for /usr/bin/gcc.

    ln -sf /usr/bin/gcc-7 /usr/bin/gcc
  • Did you actually try this on 18.04?. Because it has gcc-6 (6.5.0-2ubuntu1~18.04 ) which would install instead of the lower zesty package
    – doug
    Apr 23, 2020 at 14:41
  • @doug I actually tried it on 20.04. Since 6.4 and 6.5 is in Universe, I added instructions to disable that. I hope answer is fine now.
    – Kulfy
    Apr 23, 2020 at 15:31
  • For Focal and some other versions I got Package 'gcc-6' has no installation candidate May 6, 2020 at 16:22
  • @MaximSuslov GCC 6 isn't available in repositories of Focal. Have you added any other repository as I mentioned in my answer?
    – Kulfy
    May 7, 2020 at 15:29

Compile from source

Here I am maintaining a list of all trusted GCC packages for Ubuntu: How do I use the latest GCC on Ubuntu?

If your GCC of interest is not there, I don't see any option besides compiling your GCC from source (or better, port your software).

The easiest way is to check if crosstool-NG supports it that version. Here I've given an example: https://stackoverflow.com/questions/10412684/how-to-compile-my-own-glibc-c-standard-library-from-source-and-use-it/52454710#52454710

If not, you will just have to fight with manual build instructions found on Google e.g.: https://stackoverflow.com/questions/26305738/can-i-build-gcc-for-arm-with-an-x64-one/26306591#26306591

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.