- C/C++ code
插入模块无法成功,查了很久帖子,找不到解决方法。insmod: error inserting './hello.ko': -1 Invalid module format错误信息如下:80:/w/hello # dmesg | tail[856096.526863] hello: disagrees about version of symbol module_layout版本:80:/usr/src # uname -r3.0.13-0.27-default80:/w/hello # uname -aLinux 80 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux80:/w/hello # modinfo hello.kofilename: hello.kolicense: Dual BSD/GPLsrcversion: 31FE72DA6A560C890FF9B3Fdepends:vermagic: 3.0.13-0.27-default SMP mod_unload modversions80:/w/hello # modinfo /lib/modules/3.0.13-0.27-default/build/sound/soundcore.kofilename: /lib/modules/3.0.13-0.27-default/build/sound/soundcore.koalias: char-major-14-*license: GPLauthor: Alan Coxdescription: Core sound modulesrcversion: 8C2CC496EFFF806BFEE1D0Cdepends:vermagic: 3.0.13-0.27-default SMP mod_unload modversionsparm: preclaim_oss:int
[/code]
- C/C++ code
1 #include<linux/init.h> 2 #include<linux/module.h> 3 MODULE_LICENSE("Dual BSD/GPL"); 4 static int hello_init(void) 5 { 6 printk(KERN_ALERT "Hello, world\n"); 7 return 0; 8 } 9 static void hello_exit(void) 10 { 11 printk(KERN_ALERT "Goodbye, cruel world\n"); 12 } 13 module_init(hello_init); 14 module_exit(hello_exit);
- C/C++ code
Makefile文件 1 ifneq ($(KERNELRELEASE),) 2 obj-m :=hello.o 3 else 4 PWD := $(shell pwd) 5 KVER ?= $(shell uname -r) 6 KDIR := /lib/modules/$(KVER)/build 7 default: 8 $(MAKE) -C $(KDIR) M=$(PWD) modules 9 clean: 10 rm -rf .*.cmd *.mod.c *.ko .tmpversions 11 endif
------解决方案--------------------
模块的版本是否和正运行的kernel的版本信息一致