6

I seem to have messed up something with a manual gcc update sometime in the past, which didn't become a problem until today, when I upgraded from 14.04 to 16.04. Namely, the system seems to think that the libstdc++6 version is OK, while apt (and many other programs) complain it isn't (because the shared library is actually in the wrong version):

sudo apt-get install --fix-broken --fix-missing
apt-get: relocation error: /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0: symbol _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

The system doesn't even start a graphical mode, the above output was obtained using a non-graphical console (using Ctrl-Alt-F6), and apt itself is completely unusable, so I can't just do something like a reinstall.

How can I fix and reinstall these packages, when the program I'm using for managing them itself is affected and unusable?

1 Answer 1

7

At first, I was able to get a graphical login shell by manually copying libstdc++.so.6.0.21 into its place from a Live USB stick, and creating a link to it from libstdc++.so.6. I used this exact version because it seems to be the default for Ubuntu 16.04 and also contains the "21" mentioned in the error message ("version GLIBCXX_3.4.21").

While this seemed to satisfy the graphics stack, the same errors remained with apt and other programs depending on libstdc++6. After some trying, I could resolve the whole thing with the following steps, using dpkg to manually (un)install things:

  • Download the deb files in the right versions for 16.04:

    wget http://mirrors.kernel.org/ubuntu/pool/main/a/apt/apt_1.2.10ubuntu1_amd64.deb http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
    
  • Removing this specific version, which blocked installing the correct libstdc++6:

    sudo dpkg --force-depends -r libstdc++6:i386
    
  • Then install the "good" version from the files:

    sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb apt_1.2.10ubuntu1_amd64.deb
    
  • And finally, fix the mess I left while updating and trying things out:

    sudo apt-get install -f
    
3
  • Saved my life !
    – Ugo
    Jun 6, 2018 at 9:24
  • for 32bit. wget http://mirrors.edge.kernel.org/ubuntu/pool/main/a/apt/apt_1.2.10ubuntu1_i386.deb http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.10_i386.deb then sudo dpkg --force-depends -r libstdc++6:i386 then sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.10_i386.deb apt_1.2.10ubuntu1_i386.deb Nov 29, 2018 at 4:53
  • For Ubuntu 18.04.1 packages.ubuntu.com/bionic/amd64/libstdc++6/download had similar problem: sudo apt-get update apt-get: error while loading shared libraries: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: invalid ELF header
    – mvladk
    Jan 31, 2019 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .