Linux内核驱动程序makefile错误:“'hello.ko'不需要建立目标'hello.mod.o'的规则”]]

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

我正在研究O'Reilly的Linux设备驱动程序中的hello world模块示例。下面是我正在使用的makefile,摘自书中的示例:

# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.

ifneq ($(KERNELRELEASE),)
    obj-m := hello.o

# Otherwise, we were called directly from the command
# line, invoke the kernel build system.

else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD :=$(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

运行make时出现以下错误:

make -C /lib/modules/5.7.1-x86_64/build M=/home/sleepy/code/drivers/hello modules
make[1]: Entering directory '/usr/src/linux-5.7.1'
  MODPOST 1 modules
make[3]: *** No rule to make target '/home/sleepy/code/drivers/hello/hello.mod.o', needed by '/home/sleepy/code/drivers/hello/hello.ko'.  Stop.
make[2]: *** [scripts/Makefile.modpost:95: __modpost] Error 2
make[1]: *** [Makefile:1642: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-5.7.1'
make: *** [Makefile:15: default] Error 2

如何解决此错误?

我正在研究O'Reilly的Linux设备驱动程序中的hello world模块示例。以下是我正在使用的makefile,摘自该书中的示例:#如果定义了KERNELRELEASE,我们就可以......>

linux makefile linux-kernel driver
1个回答
0
投票

我设法使用以下命令获得了完整的版本:

obj-m := hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
© www.soinside.com 2019 - 2024. All rights reserved.