linux kernel 测试文件编译失败
学习《Linux设备驱动程序第三版.pdf》,第2章的给的测试程序,无法再虚拟机上编译成功。主要原因是makefile不正确,请帮忙修改一下。
错误提示信息:
make[1]: Entering directory `/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE'
make[2]: *** No rule to make target `/mnt/hgfs/share/kernel_code/kernel_hello.c', needed by `/mnt/hgfs/share/kernel_code/kernel_hello.o'. Stop.
make[1]: *** [_module_/mnt/hgfs/share/kernel_code] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE'
make: *** [default] Error 2
书中的makefile脚本(没有指定编译器,我不清楚应该指定那个编译器)
# If KERNELRELEASE is defined, we've been invoked from the# kernel build system and can use its language.ifneq ($(KERNELRELEASE),)obj-m := kernel_hello.o# Otherwise we were called directly from the command# line; invoke the kernel build system.elseKERNELDIR ?= /lib/modules/$(shell uname -r)/build#ehco $(KERNELDIR)PWD := $(shell pwd)#echo $(PWD)default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
#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);