Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel

I have multiple version of gcc installed on my Linux based system as follows:

ls -l /usr/bin/gcc*
lrwxrwxrwx 1 root root 7 Jan 11 05:20 /usr/bin/gcc -> gcc-4.4
-rwxr-xr-x 1 root root 239528 Sep 21 2010 /usr/bin/gcc-4.3
-rwxr-xr-x 1 root root 255536 Nov 15 2010 /usr/bin/gcc-4.4

I need to build a nvidia device driver using the same version of GNU compiler as was used to compile the currently running kernel. How do I find out the version of my GNU gcc compiler that was used by upstream Linux distribution to compile and pack my binary Linux kernel?

You need to cat the /proc/version file. This file identifies the kernel version that is currently running and gcc version used to build the kernel.

Sample Outputs From Debian GNU/Linux 6.x

Open a command-line terminal (select Applications > Accessories > Terminal), and then type the cat command:
$ cat /proc/version
Sample outputs:

Linux version 2.6.32-5-amd64 (Debian 2.6.32-41) ([email protected]) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Mon Jan 16 16:22:28 UTC 2012

Sample Outputs From CentOS / RHEL 6.x Server

Type the following command:
$ cat /proc/version
Sample outputs:

Linux version 2.6.32-220.2.1.el6.x86_64 ([email protected]) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Dec 13 16:21:34 EST 2011

Sample outputs from an Ubuntu Linux laptop

$ cat /proc/version
Sample outputs:

Linux version 4.13.0-17-generic ([email protected]) (gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)) #20-Ubuntu SMP Mon Nov 6 10:04:08 UTC 2017

How Do I Force make To Use Particular Compiler?

You need to set shell environment variable called CC to point to your C compiler. In this example set CC to gcc version 4.3.x:
$ export CC=/usr/bin/gcc-4.3
$ make

OR start building NVIDIA module using gcc-4.3:
$ export CC=/usr/bin/gcc-4.3
$ bash

This entry is 12 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:

  1. Ubuntu Linux Install GNU GCC Compiler and Development Environment
  2. Debian Linux Install GNU GCC Compiler and Development Environment
  3. CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
  4. Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
  5. Mac OS X: Install GCC Compiler with Xcode
  6. Where is My Linux GNU C or GCC Compilers Are Installed?
  7. HowTo: Compile And Run a C/C++ Code In Linux
  8. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
  9. HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
  10. How To Install ncurses Library on a Linux
  11. Linux Find Out What Compilers Are Installed or Available On The System
  12. Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
  13. Howto see output of C program in Linux or UNIX

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.