c - 编译内核模块时出现文件错误
问题描述
您好,我正在尝试编译我的第一个内核模块,但我收到一条错误消息。我的模块的 hello.c 程序如下所示:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void){
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
我的makefile如下:
obj-m := hello.o
KDIR := /lib/modules/4.19.94-ti-r42/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD)
我还想提一下,我尝试替换M=$(PWD)
为,SUBDIRS=$(PWD)
但仍然收到相同的错误。当我运行我的 make 文件时,我收到以下错误消息:
debian@beaglebone:~/LDD-3$ make
make -C /lib/modules/4.19.94-ti-r42/build M=/home/debian/LDD-3
make[1]: Entering directory '/usr/src/linux-headers-4.19.94-ti-r42'
scripts/Makefile.build:45: /home/debian/LDD-3/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/debian/LDD-3/Makefile'. Stop.
make[1]: *** [Makefile:1522: _module_/home/debian/LDD-3] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.19.94-ti-r42'
make: *** [makefile:6: default] Error 2
有谁知道我可能做错了什么?谢谢你。
解决方案
你命名了你的 makefile makefile
,我们可以从这条消息中看到:
make: *** [makefile:6: default] Error 2
内核构建系统希望您的 makefile 命名为Makefile
,如以下消息所示:
scripts/Makefile.build:45: /home/debian/LDD-3/Makefile: No such file or directory
所以我建议你使用:
mv makefile Makefile