免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3313 | 回复: 5
打印 上一主题 下一主题

简单的驱动怎么不能insmod. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-11 20:35 |只看该作者 |倒序浏览
我写的驱动很简单就是最普通的hello.
#define MODULE
#include <linux/module.h>
                                                                                
int init_module(void) {printk("<1>Hello. world\n"); return 0; }
void cleanup_module(void) {printk("<1>Goodbye cruel word\n"); }

编译:
[root@localhost study]# gcc -c hello.c

然后insmod出现下面错误,请问什么原因,谢谢!!我好郁闷. 怎么解决?
hello.o: kernel-module version mismatch
        hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8smp.

论坛徽章:
0
2 [报告]
发表于 2007-03-16 14:32 |只看该作者
原帖由 zenghp97 于 2007-3-11 20:35 发表于 1楼  
hello.o: kernel-module version mismatch
        hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8smp.

是内核模块版本不匹配的问题吧,你当前kenel是2.4.20-8smp的,而编译出来的hello.o是给2.4.20内核用的。

论坛徽章:
0
3 [报告]
发表于 2007-03-20 22:45 |只看该作者
那要怎样才能解决呢?我是新手,能不能交交我?
我就是一编译出来就不能insmod的啊?是本机编译,可在本机上都不能insmod.郁闷死了

论坛徽章:
0
4 [报告]
发表于 2007-03-28 09:45 |只看该作者

需要更改一个叫version.h的文件。

你查一下,里面有version 的设置!然后从新编译一下就行了!

论坛徽章:
0
5 [报告]
发表于 2007-03-28 17:57 |只看该作者
gcc -c hello.c 编译普通文件 没问题
LZ现在做的是kernel module 就不行了

还是找本书看看吧 先作个Makefile:
OBJ = hello
obj-m := $(OBJ).o
KERNELDIR=/lib/modules/`uname -r`/build
PWD=`pwd`
default :
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
install :
        insmod $(OBJ).ko
uninstall :
        rmmod $(OBJ).ko

clean :
        rm -rf *.o *.mod.c *.ko

我机子内核是2.6的 不知道2.4的吃不吃的下

论坛徽章:
0
6 [报告]
发表于 2007-03-28 21:22 |只看该作者
单单gcc -c 这样编译是不行的
要加这样的参数
gcc -D__KERNEL__ -DMODULE -DLINUX -I /usr/local/src/linux2.4/include -c -o hello.o hello.c

/usr/local/src/linux2.4/include是你的源代码include的路径
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP