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

Posted on in Categories last updated February 23, 2012

I‘ve multiple version of gcc installed on my systems 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:
$ 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

(Fig.01: This kernel was built using gcc version 4.3.5)

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

(Fig.02: This kernel was built using gcc version 4.4.6)

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

Leave a Comment