编译内核模块时发生文件错误

问题描述 投票:0回答:1

你好,我正在尝试编译我的第一个内核模块,但是我收到一条错误消息。我的模块的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

有人知道我在做什么错吗?谢谢。

c makefile linux-kernel debian kernel-module
1个回答
0
投票

您将您的makefile命名为makefile,正如我们从此消息中看到的:

© www.soinside.com 2019 - 2024. All rights reserved.