Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...