第一次编译使用Makefiel编译hello.c,犯了一个很低级的错误,而且还在这个错误上徘徊了好几天,浪费了很多时间。起原因是开始对Makefile理解不够,把指向内核Makefile的目录理解成hello.c文件所在的目录。可笑吧! 是的,只看视频很多东西不实际操作就是不行。
所出现的问题:
一,编译时显示:no rule to make target "modules" ,stop
二,改动之后,输入make后又出现:
make[134]: *** [all] Interrupt
make[133]: *** [all] Interrupt
make[132]: *** [all] Interrupt
make[131]: *** [all] Interrupt
make[130]: *** [all] Interrupt
make[129]: *** [all] Interrupt
make[128]: *** [all] Interrupt
make[127]: *** [all] Interrupt
make[126]: *** [all] Interrupt
make[125]: *** [all] Interrupt
进入死循环的状况。
把目录改成功后
其成功代码如下:
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR := /usr/src/linux-headers-2.6.32-38-generic
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
在输入make,编译出hello.c hello.mod.c hello.o modules.orderhello.ko hello.mod.o Makefile Module.symvers 几个文件,证明成功。