NVIDIA CUDA on Ubuntu: unsupported GNU version! gcc versions later than 5 are not supported!

After installing CUDA on Ubuntu, compiling CUDA applications with nvcc results in an error similar to this:

In file included from /usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/cuda_runtime.h:78:0,
from <command-line>:0:
/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/host_config.h:119:2: error: #error — unsupported GNU version! gcc versions later than 5 are not supported!
#error — unsupported GNU version! gcc versions later than 5 are not supported!
^~~~~}}}

Ubuntu comes with a more up-to-date GCC then CUDA can handle. To solve this issue we install GCC 4.9:

sudo apt install gcc-4.9 g++-4.9

Now GCC 4.9 and the up-to-date GCC are installed on the system. To be able to use the up-to-date GCC without CUDA, one can setup and use the „update-alternatives“ system for GCC. In this case we replace the default GCC 6 compiler:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

Now we can list the available compilers with

update-alternatives --list gcc

and set the GCC 4.9 as default with

update-alternatives --set gcc /usr/bin/gcc-4.9

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.