Disclaimer: I am fairly new to Ubuntu. I have a reasonable amount of experience with RHEL and SLES, and have had to learn Ubuntu LTS versions recently because of some ARM64 hardware that doesn't want to boot anything else.
Summary
Ubuntu releases do, indeed, often come with some components from a later GCC than the releases' default GCC. They apparently do this so that they can provide later compiler versions, if you want to use them.
- The gcc-10-base package just provides documentation.
- The libgcc-s1 package provides an important library,
libgcc_s.so.1
. That provides helper functions for code generated by the compiler: I know it as important for handling C++ exceptions being thrown through a C call stack.
- Another important library is
libstdc++.so.6
. That provides C++ support functions.
- Glibc (
libc.so.6
, libm.so.6
and other libraries) is also important, but is not tied to a GCC version.
All of these libraries have very strong compatibility rules. Essentially, a later version of the library will always be compatible with earlier versions, discounting some ancient versions from the early history of GCC and Linux.
It isn’t obvious at first why Ubuntu and Debian provide run-times that are later than the compiler, but it gets clearer when you look at the range of GCC versions available on recent Ubuntu LTS versions:
Distribution Released Debian GCC run-times Default GCC Additional GCCs
Ubuntu 16.04 Apr 2016 9.x 5.x 5.4 4.7, 4.8, 4.9
Ubuntu 18.04 Apr 2018 10.x 8.x 7.5 4.8, 5.5, 6.5. 8.4
Ubuntu 20.04 Apr 2020 11.x 9.x & 10.x 9.3 7.4, 8.4, 10.3
At that that point, it becomes reasonably obvious. Ubuntu 20.04 has the run-times for code compiled with GCC 9.x and 10.x (GCC 10.x doesn't demand any additional library functions that GCC 9.x didn't use). You can install any mixture of GCC 7.4, 8.4 and 10.3 as extra compilers, and they'll all work. The run-time libraries on Ubuntu 20.04 will support code compiled with any of those compilers.
Why not ship GCC 10.3 with Ubuntu 20.04? Run-time libraries are generally more stable than compilers. GCC 10 would have been first released (as 10.1) about the time that 20.04 was being put together. Building an LTS release with a brand-new compiler would be foolhardy; shipping new run-time libraries, after testing them with code built with GCC 9 is a lot safer, and allows GCC 10 to be added when it has stabilised.
Canonical don't provide GCC 11 for 20.04 because it doesn't have the necessary run-times. For those, you need a later Ubuntu.
How to find all this stuff out
/usr/share/doc/gcc/README.Debian
has some information, and Ununtu 20.04 is based on Debian 11 “Bullseye”.
dpkg-query --listfiles gcc-10-base
shows us that gcc-10-base only provides documentation.
dpkg-query --listfiles libgcc-s1
shows us that libgcc-s1 provides /lib/x86_64-linux-gnu/libgcc_s.so.1
, which is one of the basic run-time libraries for GCC.
The other basic run-time libraries for C/C++ are glibc, which is independent of GCC, and libstdc++. dpkg-query -list | grep libstdc
shows us two packages:
ii libstdc++-9-dev:amd64 9.3.0-17ubuntu1~20.04 amd64 GNU Standard C++ Library v3 ...
ii libstdc++6:amd64 10.3.0-1ubuntu1~20.04 amd64 GNU Standard C++ Library v3
libstdc++6
is the GCC 10.3 version; the -dev
package is the GCC 9.3 version.
dpkg-query --listfiles libstdc++-9-dev
shows us that this package provides header files, archive libraries and documentation for developing in C++ with GCC 9.
dpkg-query --listfiles libstdc++6
shows us that this package provides documentation, some Python scripts and two really important files:
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28
The .so.6
file is what programs are linked against. It is actually a softlink to the .so.6.028
file. That’s the name of the GCC 10 version of libstdc++, the GCC support library for C++. You can get the mapping between those names and GCC versions here. Scroll down, and you’ll find some tables.