insmod kernel error

virusshit 2005-11-24 02:28:25
hello.c:
#define MODULE 2.4.20-8smp
#include <linux/module.h>
int init_module(void){printk("<1>Hello World!");return 0;}
void cleanup_module(void){printk("<1>Goodbye cruel world!");}

After I compile a hello.c file into hello.o, I insmod hello.o
but find the 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.

why the error ? how to solve it?
thanks
...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tb01412 2005-11-24
  • 打赏
  • 举报
回复
更简单的方法:在insmod的时候加上-f参数
223xh 2005-11-24
  • 打赏
  • 举报
回复

编译的时候要加入当前内核版本
bekars 2005-11-24
  • 打赏
  • 举报
回复
编译的内核版本和现在运行的不一致

简单的方法,修改
/usr/include/linux/version.h

UTS_RELEASE 为 2.4.20-8
saintl 2005-11-24
  • 打赏
  • 举报
回复
/* How to compile:
* gcc -I /usr/src/linux-2.4/include -DMODULE -D__KERNEL__ -O2 -c hello.c
*/
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include <linux/kernel.h>
#include <linux/module.h>

int init_module(void)
{
printk(KERN_ALERT "Hello World!\n");
return 0; // Must return 0!
}

void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world!\n");
}

MODULE_LICENSE("GPL"); // Avoid "no license" warning.

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧