[英]Compilation error for Linux kernel module programming
我正在学习Linux内核模块编程。 我正在为此使用Beaglebone黑色。 我已经制作了简单的“ Hello World”应用程序和makefile。 我检查了我的makefile文件是否正确。 但是当我命令“ make”时,它给了我以下错误:
root@beaglebone:/home/sonu# make
make: Warning: File `Makefile' has modification time 2.2e+02 s in the future
make -C /lib/modules/3.8.13-bone70/build M=/home/sonu modules
make: *** /lib/modules/3.8.13-bone70/build: No such file or directory. Stop.
make: *** [all] Error 2
虽然我提到了一些网站。 但是,他们都要求我安装软件包。 因为我是新手。 我什至不知道如何使用以太网在Beaglebone上配置和启动Internet连接。 请帮助我,我被卡住了。 提前致谢。
代码是:
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
static int __init hello(void)
{
printk(KERN_INFO "Hello World!");
return 0;
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Bye");
}
module_init(hello);
module_exit(hello_cleanup);
Makefile是:
obj-m+=Hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$(CC) Hello.c -o test
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
rm test
看来您正在尝试为尚未安装标头的内核版本构建模块。
与其直接在规则中调用uname
将其放入可以覆盖的变量中很有帮助:
obj-m+=Hello.o
KSRC := /lib/modules/$(shell uname -r)/build
all:
make -C $(KSRC) M=$(PWD) modules
$(CC) Hello.c -o test
clean:
make -C $(KSRC) M=$(PWD) clean
rm test
现在,您可以覆盖内核头文件的实际位置:
make KSRC=/usr/src/linux-headers-4.9.2 all
您可以使用包罗万象的规则进一步简化Makefile:
obj-m+=Hello.o
KSRC := /lib/modules/$(shell uname -r)/build
all: modules
$(CC) Hello.c -o test
%:
make -C $(KSRC) M=$(PWD) $@
clean::
make -C $(KSRC) M=$(PWD) clean
$(RM) test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.