在 Ubuntu 21.04 上安装 gcc/g++ 6

在 Ubuntu 21.04 上安装 gcc/g++ 6

我正在尝试编译 Cuda 10.2,可以预见的是,gcc-10 无法编译它。使用 20.04 时很简单,添加 bionic repo、更新、安装、更新替代方案。使用 21.04 时,我无法让任何东西工作。

我尝试使用 xenial 和 bionic 的“main”和“universe”存储库,但都引发了有关 PUBKEY 的错误。我从 ubuntu 密钥服务器获取了 PUBKEY 并更新了软件包列表,没有出现错误。

sudo apt install g++-6

Package g++-6 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 'g++-6' has no installation candidate

来源.列表 ->

deb http://archive.ubuntu.com/ubuntu hirsute restricted main multiverse universe

deb http://archive.ubuntu.com/ubuntu hirsute-updates restricted main multiverse universe

deb http://archive.ubuntu.com/ubuntu hirsute-security restricted main multiverse universe

# gcc-6
deb [allow-insecure=yes] http://dk.archive.ubuntu.com/ubuntu/ bionic main universe
#deb [allow-insecure=yes] http://dk.archive.ubuntu.com/ubuntu/ xenial main universe

有人知道我如何使用 Ubuntu 21.04 实现这一点吗?我读过的每篇文章都说要添加 bionic 或 xenial repos、更新、安装。到目前为止我还没有运气。

答案1

我从浏览 Ubuntu 存储库中获取了所需的软件包(.deb)这里

以下是我手动安装 gcc/g++ 6 所需的 .deb 软件包列表。按列表顺序安装。这假设您拥有编译所需的大部分工具,并且只是想切换默认的 gcc 版本。

sudo apt install ./libisl19_0.19-1_amd64.deb
sudo apt install ./gcc-6-base_6.4.0-17ubuntu1_amd64.deb
sudo apt install ./cpp-6_6.4.0-17ubuntu1_amd64.deb

# you can grab this next package from 21.04 repos, it handles a lot of the dependancies.
sudo apt install libgcc-6-dev

# Finally
sudo apt install ./gcc-6_6.4.0-17ubuntu1_amd64.deb

# GCC-6 is now installed, you can test by gcc-6 -v
baudneo@ZMES-test:~$ gcc-6 -v
gcc version 6.4.0 20180424 (Ubuntu 6.4.0-17ubuntu1)

# Now for G++ 6
sudo apt install ./libstdc++-6-dev_6.4.0-17ubuntu1_amd64.deb
sudo apt install ./g++-6_6.4.0-17ubuntu1_amd64.deb

# G++-6 is now installed! test by g++-6 -v
baudneo@ZMES-test:~$ g++-6 -v
gcc version 6.4.0 20180424 (Ubuntu 6.4.0-17ubuntu1)

# Now it is time to configure the system to use GCC G++ 6
# This assumes you do not have other versions of gcc and g++ installed for other projects

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 100
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 100
sudo update-alternatives --set c++ /usr/bin/g++
# When you want to revert these back to default gcc-10
sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
sudo update-alternatives --set c++ /usr/bin/g++

相关内容