Is there a recommended GCC version for compiling the Linux kernel?

I find Linux kernel's header "compiler-GCC ". Does it include information about the kernel's recommended GCC version? That is, can I find information about compiling in the Linux kernel source code?

  • 1
    Are you asking what GCC versions are recommended (or supported) for compiling particular kernel versions? I recommend you edit this with more details about what you're trying to find out. Are you looking for the significance of include/linux/compiler-gcc.h in the kernel headers? Is this related to the version of GCC that was used to build a the currently running kernel binary, as shown in the output of cat /proc/version? The Linux kernel and GCC are separate projects--they're not released together. Can you edit in an explanation of what you mean by "matching kernel and gcc version"? – Eliah Kagan Jan 18 '17 at 11:44
  • I mean when compiling kernel, is there recommended compiler version? – Sung-il Jan 19 '17 at 1:22
  • Or kernel compile well with any gcc version? – Sung-il Jan 19 '17 at 1:26

You should be able to build the Linux kernel with a pretty old version of GCC, probably back as far as GCC 3.2. The top-level README file in Linux 4.9.4 mentions:

 - Make sure you have at least gcc 3.2 available.
   For more information, refer to Documentation/Changes.

And Documentation/Changes gives a list of required versions of GCC (listed as "GNU C") and the other build dependencies for Linux, as well as how to check what version of each you currently have installed:

====================== ===============  ========================================
        Program        Minimal version       Command to check the version
====================== ===============  ========================================
GNU C                  3.2              gcc --version
GNU make               3.80             make --version
binutils               2.12             ld -v
util-linux             2.10o            fdformat --version
module-init-tools      0.9.10           depmod -V
e2fsprogs              1.41.4           e2fsck -V
jfsutils               1.1.3            fsck.jfs -V
reiserfsprogs          3.6.3            reiserfsck -V
xfsprogs               2.6.0            xfs_db -V
squashfs-tools         4.0              mksquashfs -version
btrfs-progs            0.18             btrfsck
pcmciautils            004              pccardctl -V
quota-tools            3.09             quota -V
PPP                    2.4.0            pppd --version
isdn4k-utils           3.1pre1          isdnctrl 2>&1|grep version
nfs-utils              1.0.5            showmount --version
procps                 3.2.0            ps --version
oprofile               0.9              oprofiled --version
udev                   081              udevd --version
grub                   0.93             grub --version || grub-install --version
mcelog                 0.6              mcelog --version
iptables               1.4.2            iptables -V
openssl & libcrypto    1.0.0            openssl version
bc                     1.06.95          bc --version
Sphinx\ [#f1]_         1.2              sphinx-build --version
====================== ===============  ========================================

.. [#f1] Sphinx is needed only to build the Kernel documentation

It's a good idea to check the Documentation/Changes file in the kernel source you're actually planning on compiling.

With all that said, it's probably a good idea to use a relatively recent version of GCC, since newer versions have better optimizers and thus can often produce faster code, and since newer versions have more readable diagnostics so it may be easier to figure out what went wrong of your build fails.

In general, I recommend using the version of GCC that is officially packaged for your system. In Ubuntu, the version of GCC that is installed as a dependency of the build-essential metapackage should always be sufficient, at least for building kernels that aren't far newer than the kernel officially packaged for your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.