赞
踩
在学习驱动程序的过程中,做的最多的一件事情就是从文章中直接把代码copy回去,直接就Makefile了,但是也会遇到标题类似的问题:
curtis@curtis-virtual-machine:~/Desktop/test$ ls
Makefile test.c
curtis@curtis-virtual-machine:~/Desktop/test$ vim Makefile
curtis@curtis-virtual-machine:~/Desktop/test$ make
make -C /lib/modules/4.2.0-42-generic/build M=/home/curtis/Desktop/open_hook_demo modules
make[1]: Entering directory `/usr/src/linux-headers-4.2.0-42-generic'
Building modules, stage 2.
MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-headers-4.2.0-42-generic'
curtis@curtis-virtual-machine:~/Desktop/test$ ls
Makefile modules.order Module.symvers test.c
curtis@curtis-virtual-machine:~/Desktop/test$
从上面结果可以看到,虽然make没有报错,但是并没有生成ko文件,原因就在自己copy Makefile的时候出问题,从实体机copy到虚拟机的时候,少了一个字母!!!!
curtis@curtis-virtual-machine:~/Desktop/test$ cat Makefile
bj-m :=test.o
KERNEL := /lib/modules/$(shell uname -r)/build
all:
make -C $(KERNEL) M=$(shell pwd) modules
install:
make -C $(KERNEL) M=$(shell pwd) modules_install
depmod -A
clean:
make -C $(KERNEL) M=$(shell pwd) clean
原来是obj-m,复制进去成了bj-m,修改Makefile再次make:
curtis@curtis-virtual-machine:~/Desktop/test$ make
make -C /lib/modules/4.2.0-42-generic/build M=/home/curtis/Desktop/open_hook_demo modules
make[1]: Entering directory `/usr/src/linux-headers-4.2.0-42-generic'
CC [M] /home/curtis/Desktop/open_hook_demo/test.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/curtis/Desktop/open_hook_demo/test.mod.o
LD [M] /home/curtis/Desktop/open_hook_demo/test.ko
make[1]: Leaving directory `/usr/src/linux-headers-4.2.0-42-generic'
curtis@curtis-virtual-machine:~/Desktop/test$ ls
Makefile modules.order Module.symvers test.c test.ko test.mod.c test.mod.o test.o
成功生成ko文件!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。