Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

Unable to compile the kernel module

I am trying to build a simple kernel in ubuntu,following are the errors getting while doing this.

make -C /lib/modules/3.13.0-52-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-52-generic'
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-52-generic'
make: *** [all] Error 2

My Make file:

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

Can anybody help me out.

Note: I have already downloaded the kernel source code

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should set PWD variable in your Makefile before using it. E.g.

PWD = $(shell pwd)

UPDATE: Also, your Makefile mix lines for two modes: KBuild mode (obj-m := module1.o) and common makefile mode(all other lines). Your should either distinguish modes(using if) or use two different files for two modes:

Makefile:

KERNEL = $(shell uname -r)
PWD = $(shell pwd)
all: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) modules
clean: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) clean

Kbuild:

obj-m := module1.o

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...