The header file linux/version.h is empty from MRG version 2 realtime kernel

Solution Verified - Updated -


  • Red Hat Enterprise Linux 6
  • MRG-Realtime v2
  • kernel-rt- or earlier


  • The version information linux/version.h is empty
  • kernel-rt-devel package creates an empty version.h file.
  • What happened to the contents of linux/version.h


Perform either of the following options.

  1. Remove the empty version.h file

    # mv /usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64/include/linux/version.h /tmp/

2) Upgrade to kernel-rt- or newer

This is tracked in this bugzilla and fixed in HSA-2013-1264

Root Cause

The example below shows building a simple kernel module in the affected MRG kernel.

  • Module initialization for our custom module below uses an explicit variable LINUX_VERSION_CODE which is usually included in version.h

    static int hello_init(void)
        printk(KERN_ALERT "version code %d\n", LINUX_VERSION_CODE); 
            return 0;
  • Because version.h is empty, compilation fails due to the missing symbol LINUX_VERSION_CODE

    # make -C /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build M=/root/test-module modules
    make[1]: Entering directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
      CC [M]  /root/test-module/hello.o
    /root/test-module/hello.c: In function ‘hello_init’:
    /root/test-module/hello.c:11: error: ‘LINUX_VERSION_CODE’ undeclared (first use in this function)
    /root/test-module/hello.c:11: error: (Each undeclared identifier is reported only once
    /root/test-module/hello.c:11: error: for each function it appears in.)
    make[2]: *** [/root/test-module/hello.o] Error 1
  • When building out-of-tree kernel modules, the kernel can include a default search include path to gcc. This is usually hidden to reduce the complexity visible to module developers.

  • Internally, the system is adding the -I parameter to gcc for the /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build directory, along with a few other directories to search. One such directory is generated/uapi/linux/version.h which is generated during compilation.

  • The -I directive can specify multiple include directories and the first to match successfully is the included file that gcc accepts. In this circumstance it is the wrong version.h.

  • If we remove or delete the empty version.h file and then attempt to build, the following should occur:

    # make
    make -C /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build M=/root/test-module modules
    make[1]: Entering directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
      CC [M]  /root/test-module/hello.o
      Building modules, stage 2.
      MODPOST 1 modules
      CC      /root/test-module/hello.mod.o
      LD [M]  /root/test-module/hello.ko
    make[1]: Leaving directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
  • The correct versions.h is used and the module builds. The discrepancy in which version.h to use was tracked in BZ983603 and fixed in RHSA-2013-1264

  • The empty version.h file can be safely removed as part of the "make" if required (although this does mean you run make with sufficient privileges), or you can alternatively specify the FULL path to version.h as shown below:

    #include <generated/uapi/linux/version.h>
    #include <linux/version.h>  // this should include an empty file, which.. doesn't matter.
  • And then set it as a define at compile time, (likely through the makefile).

    # gcc -Wall -DVERSION_H_WORKAROUND module_name.c [...]

Diagnostic Steps

# rpm -ql kernel-rt-devel|grep linux/version.h
#define LINUX_VERSION_CODE 132641
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.