I’ve written a simple module:
#define __KERNEL__
#define MODULE
#include <linux/kernel.h>
#include <linux/module.h>
int init_module(void)
{
printk("Hello, world\n");
return 0;
}
void cleanup_module(void)
{
printk("Goodbye\n");
}
and compiling it with this command:
cc -c hello.c
but I’m getting this error:
linux/module.h: No such file or directory
any suggestions?
EDIT:
I used this commad:
cc -I/usr/src/linux-headers-3.0.0-17-generic/include -c hello.c
and it goes one step ahead, now I get this error:
In file included from /usr/src/linux-headers-3.0.0-17-generic/include/linux/kernel.h:13:0,
from hello.c:3:
/usr/src/linux-headers-3.0.0-17-generic/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.
First thing you need the kernel sources. Many confuse user space headers and kernel space headers because many of them have the same folder structure. Most of the distros only have the user space headers and not the kernel space ones.
And generally
makeis used to build a kernel module and not a barecc. Follow the simple step-by-step explainedHello Worldkernel module given here