web-dev-qa-db-fra.com

Comment mettre à niveau correctement gcc7.3 vers gcc8 dans Ubuntu 18.04.01 LTS?

Dans mon Ubuntu 18.04 LTS:

marco@PC:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

J'ai la version 7.3.0 de gcc:

marco@PC:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu    
7.3.0-21ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-
7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++
--prefix=/usr --with-gcc-major-version-only --program-suffix=-7 
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-
id --libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-
clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-
default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-
verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-
system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror 
--with-Arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 
--enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none 
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu 
--Host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-21ubuntu1~16.04)

Et je veux installer gcc-8:

marco@PC:~$ Sudo apt-get install gcc-8
[Sudo] password for marco:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-8 : Depends: cpp-8 (= 8.1.0-1ubuntu1) but it is not going to be   
installed
         Depends: gcc-8-base (= 8.1.0-1ubuntu1) but 8.1.0-5ubuntu1~16.04 
is to be installed
         Depends: libgcc-8-dev (= 8.1.0-1ubuntu1) but it is not going to 
be installed
E: Unable to correct problems, you have held broken packages.

Suite aux astuces trouvées ici askUbuntu: impossible de corriger les problèmes, vous avez mis des paquets cassés

marco@PC:~$ Sudo apt-get update
[Sudo] password for marco:
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 88.7 kB in 1s (107 kB/s)
Reading package lists... Done
marco@PC:~$ Sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
marco@PC:~$ dpkg --get-selections | grep hold
marco@PC:~$ Sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
marco@PC:~$ Sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 88.7 kB in 1s (123 kB/s)
Reading package lists... Done

Ensuite, j'ai vérifié le référentiel PPA utilisé, comme suggéré:

marco@PC:~$ apt-cache policy gcc-8 cpp-8 libgcc-8-dev
gcc-8:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu    
bionic/main AMD64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe AMD64  
Packages
cpp-8:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu  
bionic/main AMD64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe AMD64   
Packages
libgcc-8-dev:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu 
bionic/main AMD64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe AMD64      
        Packages

J'ai ensuite retiré le PPA ubuntu-toolchain-r/test:

Sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
 Toolchain test builds; see https://wiki.ubuntu.com/ToolChain
 More info: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
Press [ENTER] to continue or Ctrl-c to cancel removing it.

Mais le problème demeure:

marco@PC:~$ Sudo apt-get install gcc-8
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-8 : Depends: cpp-8 (= 8-20180414-1ubuntu2) but it is not going to be 
installed
         Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04  
is to be installed
         Depends: libgcc-8-dev (= 8-20180414-1ubuntu2) but it is not going to 
be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ Sudo apt-get install cpp-8
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cpp-8 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but 8.1.0-5ubuntu1~16.04 
 is to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ Sudo apt-get install gcc-8-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc-8-base is already the newest version (8.1.0-5ubuntu1~16.04).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

marco@PC:~$ Sudo apt-get install libgcc-8-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libgcc-8-dev : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but   
8.1.0-5ubuntu1~16.04 is to be installed
                Depends: libasan5 (>= 8.1.0-1ubuntu1) but it is not going
 to be installed
                Depends: libubsan1 (>= 8.1.0-1ubuntu1) but it is not 
 going to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ Sudo apt-get install libasan5
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libasan5 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but   
 8.1.0-5ubuntu1~16.04 is to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ Sudo apt-get install libubsan1
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libubsan1 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but     
 8.1.0-5ubuntu1~16.04 is to be installed
E: Unable to correct problems, you have held broken packages.

Donc ... il semble que pour installer gcc-8, je dois installer d'autres paquets qui dépendent d'autres paquets, qui dépendent eux-mêmes de gcc-8-base, qui est déjà correctement installé.

Et ça dit "paquets cassés" ... alors comment résoudre le problème? Dans l'attente de vos conseils et de votre aide. Marco

Mise à jour:

marco@PC:~$ Sudo apt-get install ppa-purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
ppa-purge is already the newest version (0.2.8+bzr63).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

marco@PC:~$ Sudo ppa-purge ppa:ubuntu-toolchain-r/test
Updating packages lists
PPA to be removed: ubuntu-toolchain-r test
Warning:  Could not find package list for PPA: ubuntu-toolchain-r test

marco@PC:~$ Sudo apt-get update
Hit:1 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

marco@PC:~$ Sudo apt install gcc-8-base gcc-8 cpp-8 libgcc-8-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc-8-base is already the newest version (8.1.0-5ubuntu1~16.04).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cpp-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04  
 is to be installed
 gcc-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04
 is to be installed
 libgcc-8-dev : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but    
 8.1.0-5ubuntu1~16.04 is to be installed
                 Depends: libasan5 (>= 8-20180414-1ubuntu2) but it is not
                  going to be installed
                 Depends: libubsan1 (>= 8-20180414-1ubuntu2) but it is not 
                  going to be installed
 E: Unable to correct problems, you have held broken packages.

Après avoir installé aptitude, j'ai suivi les suggestions indiquées par aptitude. Maintenant j'ai cette situation:

marco@PC:~$ Sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
  2            /usr/bin/gcc-8   80        manual mode


 marco@PC:~$ g++ -std=c++17 HelloWorld.cpp -oHelloWorld
marco@PC:~$ ./HelloWorld
Hello World!

Si je choisis d'utiliser gcc-8:

marco@PC:~$ Sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
  2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gcc-8 to provide /usr/bin/gcc (gcc) in 
manual mode
update-alternatives: warning: skip creation of /usr/bin/g++ because 
associated file /usr/bin/g++-8 (of link group gcc) doesn't exist


marco@PC:~$ Sudo aptitude install g++-8
The following NEW packages will be installed:
  g++-8 libstdc++-8-dev{a}
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,623 kB of archives. After unpacking 43.7 MB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://us.archive.ubuntu.com/ubuntu bionic/universe AMD64 libstdc++-8-
dev AMD64 8-20180414-1ubuntu2 [1,536 kB]
Get: 2 http://us.archive.ubuntu.com/ubuntu bionic/universe AMD64 g++-8 AMD64 
8-20180414-1ubuntu2 [8,088 kB]
Fetched 9,623 kB in 1s (7,165 kB/s)
Selecting previously unselected package libstdc++-8-dev:AMD64.
(Reading database ... 92421 files and directories currently installed.)
Preparing to unpack .../libstdc++-8-dev_8-20180414-1ubuntu2_AMD64.deb ...
Unpacking libstdc++-8-dev:AMD64 (8-20180414-1ubuntu2) ...
Selecting previously unselected package g++-8.
Preparing to unpack .../g++-8_8-20180414-1ubuntu2_AMD64.deb ...
Unpacking g++-8 (8-20180414-1ubuntu2) ...
Setting up libstdc++-8-dev:AMD64 (8-20180414-1ubuntu2) ...
Setting up g++-8 (8-20180414-1ubuntu2) ...
Processing triggers for man-db (2.8.3-2) ...


marco@PC:~$ Sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
* 2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number:
update-alternatives: warning: forcing reinstallation of alternative /usr/bin
/gcc-8 because link group gcc is broken

Maintenant, après le redémarrage, il semble fonctionner:

marco@PC:~$ Sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

      Selection    Path            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
* 2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number:
marco@PC:~$ g++ -std=c++17 HelloWorld.cpp -oHelloWorld
marco@PC:~$ ./HelloWorld
Hello World!

marco@PC:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu   
8-20180414-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs  
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr   
--with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with- 
ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-8 --program-prefix=x86_64-  
linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib  
--without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-
nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-
libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-
object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-
default-pie --with-system-zlib --with-target-system-zlib --enable-objc-
gc=auto --enable-multiarch --disable-werror --with-Arch-32=i686 --with-
abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-
tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver
 --enable-checking=release --build=x86_64-linux-gnu --Host=x86_64-linux-gnu 
--target=x86_64-linux-gnu

Thread model: posix
gcc version 8.0.1 20180414 (experimental) [trunk revision 259383] (Ubuntu 
8-20180414-1ubuntu2)
3
user2315094

Les référentiels incompatibles à partir de 16.04 de vos sources de logiciels interfèrent avec l'installation d'autres paquets dans Ubuntu 18.04 et provoquent un message d'erreur concernant les paquets cassés. Supprimez donc les dépôts incompatibles avec ppa-purge de vos sources de logiciels. .

Ensuite, vous pourrez installer les paquets dont vous avez besoin à partir des référentiels Ubuntu 18.04 par défaut. Ouvrez le terminal et tapez:

Sudo apt-get install ppa-purge
Sudo apt update 
Sudo apt install aptitude 
Sudo aptitude install libubsan1 libasan5 libgcc-8-dev gcc-8-base gcc-8 cpp-8 g++-8 

Suivez les suggestions d’aptitude s’il existe un problème de dépendance après l’exécution de la dernière commande, car aptitude suggère un peu d’astuce pour résoudre les problèmes de dépendance causés par des paquets cassés.

3
karel