3

On Ubuntu 22.04, the default GNU C compiler version is gcc-11. However, it appears that the latest default kernel version (6.5.0-14-generic as of writing this question) is built using gcc-12. Why is this the case? It feels like it's likely to result in issues related to mixing compilers and has already caused me headaches with kernel modules and dkms.

2 Answers2

3

NOTE: The 6.5 Kernel reports being built as x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) and this should be OK. This is because the kernel is not built on your system during install. See https://askubuntu.com/a/1171939/231142 for more info. During any builds it might give you a warning about not matching the installed version since they are not named the same. Installed version reports as gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04)


gcc-12 should already be installed, but if it isn't, you can install it or reinstall it by running:

sudo apt install --reinstall gcc-12

Then all you should have to do is update the link for gcc to go to the gcc-12 binary:

sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc

You can set it back to 11 as well by doing the following:

sudo ln -s -f /usr/bin/gcc-11 /usr/bin/gcc

You can check it by running gcc --version.

terrance@terrance-ubuntu:~$ gcc --version
gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Terrance
  • 41,612
  • 7
  • 124
  • 183
  • I appreciate the information in this answer. The note at the top particularly answers another question I had. However, this answer doesn't exactly answer the question. My question is: why is there a mismatch between the default GCC version and the one used to build the kernel and is this scenario not a potential problem? Shouldn't this mismatch be avoided? – Adam Sperry Jan 15 '24 at 19:42
  • @AdamSperry It is up to Canonical when they build the Kernel with whatever GCC version they may be using before it is pushed to the system. The versions technically are the same, just the name of the compiler itself is different. – Terrance Jan 15 '24 at 19:52
  • @AdamSperry it's just warnings anyways so it shouldn't be causing any issues. However, if you feel that it should match so it doesn't cause the warnings you are more than welcome to file a bug against the Kernel. – Terrance Jan 15 '24 at 20:08
  • But the versions are not the same. The default gcc version on Ubuntu 22.04 is gcc-11. The default kernel (6.5.0-14-generic as of today) is built with gcc-12. Are you saying gcc-11 is technically the same as gcc-12? – Adam Sperry Jan 15 '24 at 21:03
  • @AdamSperry No. I was saying that gcc-12 should already be installed. It is just that the link to the /usr/bin/gcc is not updated to point to gcc-12. They should both be in the path and if you type in gcc-12 --version it should return to you the installed version. The same goes with gcc-11 --version should return the version. If you run ls -al /usr/bin/gcc it should return similar to lrwxrwxrwx 1 root root 15 Jan 13 10:42 /usr/bin/gcc -> /usr/bin/gcc-11 – Terrance Jan 15 '24 at 21:06
  • Yes I understand that. But I shouldn't have to change these links to get a kernel module to build. It's fine if I'm manually building/installing a kernel module because then I can change the links back afterward, but it's not easy to make this happen correctly when using DMKS and leaving the default compiler at gcc-12 when the entire distribution is built around gcc-11 seems like a bad idea because you're going to be mixing compilers when building anything else against binaries from the distribution right? – Adam Sperry Jan 15 '24 at 21:14
  • @AdamSperry I haven't stumbled into any issues so far and I have updated my link to gcc-12. I can't tell you as I have not experienced any issues in building at all. The only thing I have seen is where someone was trying to install VMWare and it was requiring gcc 12.3.0 as it apparently looks at the /usr/bin/gcc link. I updated my link a while ago to gcc-12 and as a test I followed the same installation https://askubuntu.com/questions/1499824/ubuntu-22-04-3-vmware-kernel-module-updater#comment2627853_1499824 without any issues and no complaints of 12.3.0 not found. – Terrance Jan 15 '24 at 21:27
  • Well it is certainly useful to know that you have not had problems changing your default to gcc-12 – Adam Sperry Jan 15 '24 at 21:43
0

There are a lot of mismatches in Ubuntu 22.05 GNU compiler versions and the copmpiler used to build the kernel.

ls -l /usr/bin/gcc* ... ls -l /usr/bin/g++* ...