错误提示:
/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
cuda-10.1的版本不支持gcc的版本大于8的,所以需要将编译器gcc和g++降级。
1.查看当前gcc版本
gcc -v
版本为:11.4.0
2. 直接安装gcc-7和g++-7
sudo apt-get install gcc-7 g++-7
遇到错误:
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
错误原因:使用的apt镜像库没有这个软件。
3. 添加apt库
运行
sudo nano /etc/apt/sources.list
在最后添加
# stable add by , in order to install g++7
deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe
然后
更新apt库
sudo apt update
安装gcc和g++
sudo apt-get install gcc-7 g++-7
至此,gcc-7和g++-7安装成功
4.切换gcc和g++版本
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
以上命令将gcc-7版本设置为默认gcc,并将其优先级设置为80。在多个gcc版本同时存在的情况下,系统将按照优先级自动选择使用哪个版本。