gpt4 book ai didi

gcc - 如何在 ubuntu 上使用更新版本的 gcc?

转载 作者:行者123 更新时间:2023-12-05 05:07:31 24 4
gpt4 key购买 nike

我正在运行 ubuntu 18.04,我目前有:

(tensorflow_p36) ubuntu@user:~$ gcc --version
gcc (GCC) 4.8.5

(tensorflow_p36) ubuntu@user:~$ gcc-8 --version
gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0

(tensorflow_p36) ubuntu@user:~$ which gcc
/home/ubuntu/anaconda3/envs/tensorflow_p36/bin/gcc

我正在尝试使用最新的 gcc-8 作为显示 here .但是当我运行时

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8

我收到以下错误:

update-alternatives: error: alternative g++ can't be slave of gcc: it is a master alternative

当我尝试时:

(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --config gcc

我收到另一个错误:

update-alternatives: error: no alternatives for gcc

我怎么没有gcc的替代品?任何关于如何解决此错误并将 gcc-8 配置为默认 gcc 安装的建议都将不胜感激。


从 conda 环境外部运行 which gcc 不会返回任何内容:

ubuntu@user:~$ which gcc
ubuntu@user:~$

但是

ubuntu@user:~$ gcc-8 --version
gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0

更新。我正在按照下面的有用建议尝试以下操作,但仍然无济于事。

(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 40
(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 60
(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --config g++
There are 3 choices for the alternative g++ (providing /usr/bin/g++).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/x86_64-linux-gnu-g++-7 100 auto mode
1 /usr/bin/g++-4.8 60 manual mode
2 /usr/bin/g++-8 40 manual mode
3 /usr/bin/x86_64-linux-gnu-g++-7 100 manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/g++-8 to provide /usr/bin/g++ (g++) in manual mode

到目前为止一切顺利,但是当我测试 g++ 版本时,它仍然是一样的!

~$ g++ --version
g++ (GCC) 4.8.5

最佳答案

您来这里可能是因为 nvidia 出了点问题。(我在使用 cudatoolkit 11.4,实际上降级让我摆脱了麻烦——你的里程可能会有所不同。)

sudo apt install gcc-9 g++-9
sudo mkdir /usr/local/cuda/bin
sudo ln -s /usr/bin/gcc-9 /usr/local/cuda/bin/gcc

警告 - 我建议使用 timeshift 备份您的工作系统。 https://github.com/teejee2008/timeshift

这将为您提供最新的 gcc 11

sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo apt-get install g++-11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 100
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 50
sudo update-alternatives --set g++ /usr/bin/g++-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo update-alternatives --set cpp-bin /usr/bin/cpp-11
gcc --version
gcc (Ubuntu 11-20210417-1ubuntu1) 11.0.1 20210417

版权所有 (C) 2021 Free Software Foundation, Inc.

关于gcc - 如何在 ubuntu 上使用更新版本的 gcc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59010563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com