Chinaunix首页 | 论坛 | 博客
  • 博客访问: 433220
  • 博文数量: 55
  • 博客积分: 2235
  • 博客等级: 大尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-14 13:34
文章分类
文章存档

2012年(2)

2011年(26)

2010年(1)

2009年(20)

2008年(6)

我的朋友

分类: LINUX

2011-03-23 16:56:02

今天试着在ubuntu10.4来配置ldd3的环境。出现如下问题:
现像:

makefile:

# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.
ifneq ($(KERNELRELEASE),)
 obj-m:=hello_driver.o
else

 KERNELSRC:=/home/foxwolf/study/ldd3/linux-2.6.32

modules:
 $(MAKE) -C $(KERNELSRC) SUBDIRS=$(PWD) $@

clean:
 rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules clean

endif

hello$ make
make -C /home/foxwolf/study/ldd3/linux-2.6.32 SUBDIRS=/home/foxwolf/study/ldd3/hello modules
make[1]: 正在进入目录 `/home/foxwolf/study/ldd3/linux-2.6.32'
  CC [M]  /home/foxwolf/study/ldd3/hello/hello_driver.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/foxwolf/study/ldd3/hello/hello_driver.mod.o
  LD [M]  /home/foxwolf/study/ldd3/hello/hello_driver.ko
make[1]:正在离开目录 `/home/foxwolf/study/ldd3/linux-2.6.32'

hello$ sudo insmod hello_driver.ko
insmod: error inserting 'hello_driver.ko': -1 Invalid module format

hello$ dmesg | tail -n 1
[92405.331585] hello_driver: disagrees about version of symbol module_layout

hello$ modinfo hello_driver.ko
filename:       hello_driver.ko
license:        Dual BSD/GPL
srcversion:     31FE72DA6A560C890FF9B3F
depends:       
vermagic:       2.6.32 SMP mod_unload modversions 586

hello$ cat hello_driver.mod.c
#include
#include
#include

MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
 .name = KBUILD_MODNAME,
 .init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
 .exit = cleanup_module,
#endif
 .arch = MODULE_ARCH_INIT,
};

static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
 { 0xf1a7e7ff, "module_layout" },
 { 0xb72397d5, "printk" },
 { 0xb4390f9a, "mcount" },
};

static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";


MODULE_INFO(srcversion, "31FE72DA6A560C890FF9B3F");

 

 

网络上查找信息,说是当前编译的源码版本跟系统内核的版本没有一致。也有些人说是编译器版本不同造成的,觉得不太可能。而且也有高人指点,明确这跟编译器无关,就是源码问题。网上找的帖子确实未能解决掉这个问题。


解决办法:使用PC自带的头文件,首先用uname -a查看自己内核版本,比如我的是:
Linux yangm-u104 2.6.32-29-generic #58-Ubuntu SMP Fri Feb 11 19:00:09 UTC 2011 i686 GNU/Linux
于是在Makefile中将路径改为:
KERNELDIR := /lib/modules/2.6.32-29-generic

或者KERNELDIR := /lib/modules/$(shell uname -r)/build

再次编译,成功通过。

阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~