I am trying to compile a kernel module from this example, on a Debian 12 system which was just installed.
The example code requires the following header files, and of course these header files also include many other header files:
#include <linux/init.h>
#include <linux/module.h>
So I installed the linux-headers-amd64
package because it has the kernel headers I need to compile. The problem is that the kernel headers get installed into /usr/src/linux-headers-6.1.0-21-common/include/linux/
. So I get the following error when I try to compile:
fatal error: linux/init.h: No such file or directory
1 | #include <linux/init.h>
| ^~~~~~~~~~~~~~
I could just create a symbolic link called linux
in /usr/include/
except that there is already a directory there with that name. So I tried changing my #include
statement like this:
#include "/usr/src/linux-headers-6.1.0-21-common/include/linux/init.h"
But then all the other included header files are not found:
fatal error: linux/compiler.h: No such file or directory
5 | #include <linux/compiler.h>
| ^~~~~~~~~~~~~~~~~~
So, how is this supposed to work? Did I install the wrong package for the kernel header files? How can I compile this without completely rearranging every header file on my system?