LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 631|回复: 1

请问如何解决mdk下编译内核时遇到的版本控制问题

[复制链接]
发表于 2005-1-3 06:41:54 | 显示全部楼层 |阅读模式
按照<linux设备驱动程序>一书中的最入门例程hello.c做尝试,结果也如该书所言出了版本控制的问题:
[root@localhost mine]# gcc -c hello_module.c
[root@localhost mine]# insmod ./hello_module.o
./hello_module.o: kernel-module version mismatch
        ./hello_module.o was compiled for kernel version 2.4.22
        while this kernel is version 2.4.22-10mdk.
作者说"强烈建议读者在运行示例代码前将自己的内核编译为不支持版本控制功能",但他给的参考网页(www.linux.it/kerneldocs/kconf)已经不存在了.
我是菜鸟,头一次接触内核,请达人指教
发表于 2005-1-3 10:45:29 | 显示全部楼层
这是我以前写的例子,你看看,在redhat 9.0上面编译的,内核是2.4.x的。

/* FILE   : demo.c
*
* USAGE  : How to write module driver
*
* AUTHOR : Bismar@HUST
*/

#ifndef  __KERNEL__
#define  __KERNEL__
#endif

#ifndef  MODULE
#define  MODULE
#endif

#include <linux/fs.h>
#include <linux/kernel.h>

#define  __NO_VERSION__
#include <linux/module.h>
#include <linux/version.h>

char kernel_version[] = UTS_RELEASE;

#if CONFIG_MODVERSIONS==1
#define  MODVERSIONS
#include <linux/modversions.h>
#endif

#ifdef   CONFIG_SMP
#define  __SMP__
#endif

#define  __DEBUG__

/*
* Initialize the module
*
*/
int __init init_device(void)
{
#ifdef   __DEBUG__
        printk(KERN_DEBUG "Hello,Linux driver world! \n");
#endif

        return 0;
}

/*
* Cleanup - undid whatever init_module did
*
*/
void __exit cleanup_device(void)
{
#ifdef   __DEBUG__
        printk(KERN_DEBUG "Goodbye cruel world !\n");
#endif
}


/*
* Init and exit function decleare
*
*/
module_init(init_device);
module_exit(cleanup_device);


/*
* Declare licence to avoid warnings
*
*/
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Bismar@HUST");
MODULE_DESCRIPTION("How to write a module driver");
MODULE_SUPPORTED_DEVICE("No device or every device supported");

makefile的内容:
#
# makefile for demo
#
# Bismar@HUST

CC = gcc

CINCLU = /usr/src/linux-2.4/include

CFLAGS = -D__KERNEL__ -DMODULE -DLINUX -c -O2 -Wall -I$(CINCLU)

all: main.o

%.o:%.c
        $(CC) $(CFLAGS) $< -o $@


.PHONY: clean

clean:
         rm -f *.o
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表