so I have Raspbian in my RaspberryPi and I'd like to compile a simple network driver that I'm developing. For now, I just have a simple file including the headers, to make sure I installed the kernel headers correctly. It fails though:

#define MODULE
#define __KERNEL__

#include <linux/module.h>
#include <linux/config.h>

#include <linux/netdevice.h>

int main() {
    return 0;

To install the kernel headers I simply followed this steps:

  • $ uname -r (which returned 4.4.50+)
  • Downloaded from here the file linux-headers-4.4.50+_4.4.50+-2_armhf.deb
  • $ sudo dpkg -i linux-headers-4.4.50+_4.4.50+-2_armhf.deb (this failed because I didn't have the correct dependencies installed, bc was missing).
  • $ sudo apt-get install bc
  • $ sudo dpkg -i linux-headers-4.4.50+_4.4.50+-2_armhf.deb

And now I have the folder /usr/src/linux-headers-4.4.50+/ but running sudo cc -I/usr/src/linux-headers-4.4.50+/include/ -Wall -c mydriver.c fails.

$ sudo cc -I/usr/src/linux-headers-4.4.50+/include/ -Wall -c mydriver.c
In file included from /usr/src/linux-headers-4.4.50+/include/linux/kernel.h:6:0,
             from /usr/src/linux-headers-4.4.50+/include/linux/list.h:8,
             from /usr/src/linux-headers-4.4.50+/include/linux/module.h:9,
             from mydriver.c:4:
/usr/src/linux-headers-4.4.50+/include/linux/linkage.h:7:25: fatal error: asm/linkage.h: No such file or directory
    #include <asm/linkage.h>
compilation terminated.

Using $ sudo gcc -c lum.c -I/usr/src/linux-headers-4.4.50+/include/ also has the same output.

Does anyone know what I'm missing?

By the way, doing sudo apt-get install raspberrypi-kernel-headers installs the headers for v 4.9.something, and updating to that kernel version is not an option.


EDIT: The version of the gcc is gcc (Raspbian 4.9.2-10) 4.9.2 and I checked which version was used to compile the kernel and they differ (4.9.3).

UPDATE: Just to try, I took another Raspberry Pi and followed this steps:

$ sudo apt-get -u upgrade
$ cat /proc/version (shows 4.9.24+)
$ sudo apt-get install raspberrypi-kernel-headers
$ gcc -c lum.c -I /usr/src/linux-headers-4.9.24+/include/

And I get the same error /usr/src/linux-headers-4.9.24+/include/linux/linkage.h:7:25: fatal error: asm/linkage.h: No such file or directory #include <asm/linkage.h>

So as I can see, it has nothing to do with the kernel version

  • @Milliways but shouldn't I be able to develop a driver for this specific version without problems? – lpares12 May 7 '17 at 9:52

Your Answer

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

Browse other questions tagged or ask your own question.