LinuxSir.cn,穿越时空的Linuxsir!

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

LINUX内核模块编程问题(新人请教)

[复制链接]
发表于 2004-9-10 18:54:51 | 显示全部楼层 |阅读模式
我刚学LINUX内核模块编程,照书上例子编译如下:
helllo.c
/* hello.c
* Copyright (C) 1998 by Ori Pomerantz
*
* "Hello, world" - the kernel module version.
*/

/* The necessary header files */

/* Standard in kernel modules */
#include <linux/kernel.h>   /* We're doing kernel work */
#include <linux/module.h>   /* Specifically, a module */
/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif        

/* Initialize the module */
int init_module()
{
  printk("Hello, world - this is the kernel speaking\n");

  /* If we return a non zero value, it means that init_module
failed and the kernel module can't be loaded */
  return 0;
}
/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
  printk("Short is the life of a kernel module\n");
}
/* end of hello.c*/


然后编译gcc -D__KERNEL__ -DLINUX -DMODULE -c hello.c
通过后,用/sbin/insmod进行装载,出现了以下的error:
hello.o: kernel-module version mismatch
        hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8.

它说内核版本不匹配,怎么回事?怎样改正?:help
发表于 2004-9-10 19:57:50 | 显示全部楼层
你不懂英文吗。。。?

你是在哪个内核下编译模块的。。。

在这个新的模块下运行的。。。。

so
发表于 2004-9-11 02:55:07 | 显示全部楼层
我的内核版本: 2.4.20-8
上面已给出,但是本菜鸟不知如何操作或修改代码以编译通过,烦劳大虾具体一点。
(我的系统是RED HAT9.0,内核为默认版本,没有升级过)
发表于 2004-9-11 02:57:55 | 显示全部楼层
补充下:楼主就是我,帖子是在LINUX下注册ID时发的,现在回到WINDOWS发帖,ID倒变了。

希望帮助本菜鸟。
发表于 2004-9-11 10:28:35 | 显示全部楼层
这个问题以前有人问过。好好搜索一下本版,肯定能找到答案。
发表于 2004-10-3 09:47:43 | 显示全部楼层
In the compilation command, please use options
         1)  -nostdinc
          2) -I/usr/src/linux-2.4/include   /*where you new kernel source is.*/

The command would look like
   # cc  ... -nostdinc  -I/usr/src/include-2.4/include

Option 1 asks the cc compiler not to include header file from the standard ones. Option 2 asks the compiler to include headers from the kernel source code upon which you want to build.  And "/usr/src/linux-2.4" is likely a symbolic link to the actual directory where your kernel source resides.

Should solve your problem. Good luck.
发表于 2004-10-3 17:56:21 | 显示全部楼层
奇怪,怎么用我的号发的,呵呵
发表于 2004-10-4 10:44:48 | 显示全部楼层
herberteuler和楼主不是同一个人吗?
发表于 2004-10-4 12:16:28 | 显示全部楼层
不是啊,我也不知道是怎么回事儿。
发表于 2004-10-4 16:39:28 | 显示全部楼层
难道有人能冒充ID?!!
如果是这样,问题可就大了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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