Error message:
/usr/local/cuda-10.1/include/crt/host_config.h:129:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
129 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
error: command '/usr/local/cuda-10.1/bin/nvcc' failed with exit code 1
The cuda-10.1 version does not support gcc versions greater than 8, so the compilers gcc and g++ need to be downgraded.
1. Check the current gcc version
gcc -v
The version is: 11.4.0
2. Install gcc-7 and g++-7 directly
sudo apt-get install gcc-7 g++-7
Encountered error:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package g++-7 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Package gcc-7 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'gcc-7' has no installation candidate
E: Package 'g++-7' has no installation candidate
Reason for the error: The apt mirror library used does not have this software.
3. Add apt library
run
sudo nano /etc/apt/sources.list
add at the end
# stable add by , in order to install g++7
deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe
Then
更新apt库
sudo apt update
安装gcc和g++
sudo apt-get install gcc-7 g++-7
At this point, gcc-7 and g++-7 are successfully installed.
4. Switch gcc and g++ versions
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 80
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 80
The above command sets the gcc-7 version as the default gcc and sets its priority to 80. When multiple gcc versions exist at the same time, the system will automatically choose which version to use according to priority.