21

I build embedded machines that run an RT_PREMPT version of Linux. It's an Ubuntu 10.04 installation running an Linux 2.6 kernel. Yes, it's an old kernel, but I'm stuck with it for awhile.

When I compiled the kernel, I used gcc version 4.4. On this system, there is a kernel module I have been compiling successfully for three years.

From my Makefile...

all:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) \
    modules

My current project requires support for c++14, so I updated gcc and g++ to version 5.1.0 by building from source. All my user-mode software compiles, but when I went to build an updated version of my kernel module, I get the following error right away:

make[1]: Entering directory `/usr/src/linux-headers-2.6.32-54-generic'
  CC [M]  /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.o
In file included from include/linux/compiler.h:40:0,
             from include/linux/stddef.h:4,
             from include/linux/list.h:4,
             from include/linux/module.h:9,
             from /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.c:31:
include/linux/compiler-gcc.h:86:30: fatal error: linux/compiler-gcc5.h: No such file or directory

In short:

fatal error: linux/compiler-gcc5.h: No such file or directory

If I use gcc 4.4 again (I left it installed on my computer in a different directory), it compiles and runs perfectly.

Obviously, I'm missing something. Is it not possible to compile a kernel module with a newer version of the compiler than what the operating system was compiled with? That seems unlikely to me. Is there a configuration step I'm missing? Is there a system variable I need to update? Are there extra headers I'm supposed to download? I ran apt to update build-essential, but it was up to date. I have the source and headers for the kernel on my system. I'm not sure what else I would download.

Any insights to this problem are greatly appreciated. Thank you in advance.

2 Answers 2

20

Your kernel version is too old and it is missing linux/compiler-gcc5.h.

The header is included from linux/compiler-gcc.h and its name is generated by preprocessor macro based on current compiler version:

#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)

This header was introduced around version 3.18.

You might try to get this file from a newer kernel source and put in into include/linux.

9
  • 3
    Upvoted, but I'm guessing copying compiler-gcc4.h into compiler-gcc5.h is also worth a try.
    – abligh
    Commented Apr 28, 2015 at 20:56
  • 1
    Grabbed it from here: raw.githubusercontent.com/torvalds/linux/master/include/linux/compiler-gcc5.h and copied it into the headers directory for my kernel. Solved the problem; thanks!
    – user761576
    Commented Apr 28, 2015 at 20:56
  • 11
    @abligh You are right. Or echo "#include <linux/compiler-gcc4.h>" > include/linux/compiler-gcc5.h.
    – baf
    Commented Apr 29, 2015 at 8:19
  • Hey guys, I would really like some help. I'm trying to compile linux 2.6.31. I expects compiler-gcc6.h I tried copying gcc5 into gcc6.h Doesn't work. Ends up in a slew of errors. Any other suggestions?
    – gideon
    Commented Dec 30, 2016 at 11:39
  • @gideon It depends on errors you receive. I suggest you ask new question giving more details.
    – baf
    Commented Dec 30, 2016 at 14:19
0

Open a terminal and type:

$ ls -r /usr/src/linux-headers-$(uname -r)/include/linux/ | \
  grep -P "compiler-gcc\d.h" | \
  head -n 1

this will hopefully output the latest gcc header suitable for your linux kernel.

In my case it is compiler-gcc4.h. Now you can link this file to compiler-gcc5.h in the following way:

$ sudo ln -s /usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc4.h \
             /usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc5.h

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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