2
votes

I am unable to compile a linux kernel module,

Given the following source:

/* hello.c */

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

int init_module(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world\n");
}

/* end of hello.c */

and the following Makefile:

obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

When I type make while in the same directory as the source and make files, I get the message: 'Nothing to be done for `all' The compilation seems to stop here and no object file is created.

Now just for testing, I tried a new simpler Makefile: TARGET := hello ${TARGET}.o: ${TARGET}.c

Running make gives me the new error:hello.c:1: fatal error: linux/module.h: No such file or directory.

however this file IS available in the folder:

/usr/src/linux-headers-2.6.35-22/include/linux 

and also in

/usr/src/linux-headers-2.6.35-22-generic/include/linux

as is the kernel.h file

What am I missing, any ideas?

Thanks in advance

1

1 Answers

3
votes

You are missing a tab between the start of the line and "make -C ..."