linux kernel module programming
i have some trouble compiling a module.. i'm using kernel 2.6 and am trying to compile the following file named hello.c:
----------------------------------------------------------------
Code:
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk("<1>Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk("Goodbye world 1.\n");
}
----------------------------------------------------------------
to compile it i'm doing like they say in the kernel source code documentation, i have the following Makefile:
----------------------------------------------------------------
obj-m := hello.o
----------------------------------------------------------------
and use this comando to compile it:
make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
it gives tons of errors, but the first its comlaining about not beeing able to find the module.h file included...
i tryied to include them specifying a full path but nothing worked...
anyone has a solution?? i would be very very very thankfull:)
this is how things are....
i have a fedora core 2 full installed in my pc, so i supose i have the latest tools....
my current code is (hello.c):
Code:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk("Hello World!\n");
return 0;
}
static void hello_exit(void)
{
printk("Good bye!\n");
}
module_init(hello_init);
module_exit(hello_exit);
my make file is (Makefile) :
Code:
#
# Makefile for hello.c file
#
KDIR:=/lib/modules/$(shell uname -r)/build
obj-m:=hello.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(RM) .*.cmd *.mod.c *.o *.ko -r .tmp*
i just do a make to build the all thing
it makes a hello.o
i do a insmod ./hello.o
and the reulst is:
insmod: error inserting './hello.o': -1 Invalid module format