10

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?

4 Answers 4

13

In the make file, just change SUBDIRS=$(PWD) into M=$(shell pwd)...

Works like charm

1
  • 1
    SUBDIRS=$(PWD) does not exist in my make file
    – Salem F
    Jan 3, 2021 at 14:23
4

i386 headers required:

sudo apt-get install linux-headers-$(uname -r | sed 's/\(.*\)-[a-z]*/\1/'):i386

Example:

sudo apt-get install linux-headers-5.4.0-42:i386
5
  • 3
    Why all the downvotes? Someone help me out here please to understand what the problem is with this answer. Sep 28, 2020 at 8:20
  • This actually solved my issue. I do not understand why people downvoted this Dec 6, 2020 at 21:26
  • 1
    Find your kernel version with uname -r, cut out the "-generic" part.
    – ki9
    Feb 24, 2021 at 2:21
  • 1
    Well simply because it doesn't work: Unable to locate package linux-headers-5.4.0-81-generic:i386
    – Eric
    Aug 18, 2021 at 19:31
  • 1
    Try linux-headers-5.4.0-81:i386 instead. Works here.
    – Adam
    Oct 18, 2021 at 19:51
0

to get headers files for your particular kernel... you may have more success with a slightly less clever version of @Thantelius answer:

apt search linux-headers-$(uname -r)
apt install <package name showing in the search>

however in most recent/major distros, headers should be installed by default

0

After a long time with this problem, my solution was to rename the makefile from makefile to Makefile.

2
  • It shouldn't make a difference, see this answer to Should I name "makefile" or "Makefile"?: By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile. Oct 2, 2021 at 6:15
  • I tested both multiple times. It indeed only works with ‘Makefile’.
    – Albi
    Oct 2, 2021 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .