I am using Ubuntu 12.04. I wrote a simple hello world kernel module (hello.c
). I wrote the folllowing makefile for it:
obj-m+=hello.o
KDIR:= /usr/src/linux-headers-3.2.0-24-generic-pae
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
But this error cropped up when I did make from kernel:
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-24-generic-pae'
make[2]: *** No rule to make target `arch/x86/tools/relocs.c', needed
by `arch/x86/tools/relocs'. Stop.
hello.c
and makefile
are in /Documents/module_prog
. I ran make
from that directory.
What is causing this error and how can I fix it?
In the make file, just change
SUBDIRS=$(PWD)
intoM=$(shell pwd)
...Works like charm
i386 headers required:
Example:
to get headers files for your particular kernel... you may have more success with a slightly less clever version of @Thantelius answer:
however in most recent/major distros, headers should be installed by default
After a long time with this problem, my solution was to rename the makefile from
makefile
toMakefile
.