我正在研究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,我们就可以......>
我设法使用以下命令获得了完整的版本:
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