从其构建内核模块和向其插入模块的内核应具有相同的版本。如果您不想照顾这件事,可以使用以下Makefile。
obj−m += hello−world.oall: make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modulesclean: make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean
现在,您可以构建并尝试插入模块。
我建议您尽可能在此行之前成为root
$ sudo cp /boot/config-2.6.38-8-generic ./.config
$su#cp /boot/config-2.6.38-8-generic ./.config#insmod hello_world.ko
另外,您也可以使用以下make文件
TARGET := hello-worldWARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypesINCLUDE := -isystem /lib/modules/`uname -r`/build/includeCFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}CC := gcc-3.0${TARGET}.o: ${TARGET}.c.PHONY: cleanclean: rm -rf ${TARGET}.o


