免费注册 查看新帖 |

Chinaunix

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

一个简单Linux内核模块遇到问题.帮帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-25 16:24 |只看该作者 |倒序浏览
/*
* File : hello_mod.c
* a simple module example
* date : 2005.4.25
*/
#include <linux/kernel.h>;
#include <linux/module.h>;
#if CONFIG_MODVERSIONS==1
//#define MODVERSIONS
#include <linux/modversions.h>;
#endif

int init_module()
{
  printk("hello world\n";
  printk("i have running in kernel module\n";
  return 1;
}
int clearup_module()
{
  printk("i will shut down myself in kernel module\n";
  return 1;
}
编译:
gcc -c hello_mod.c
加载:
insmod hello_mod
出现错误提示:
hello_mod.o: couldn't find the kernel version the module was compiled for
请教该如何解决???在线等...

论坛徽章:
0
2 [报告]
发表于 2005-04-25 18:59 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

#include <linux/kernel.h>;
#include <linux/module.h>;
#if (CONFIG_MODVERSIONS==1 )
#define MODVERSIONS
#include <linux/modversions.h>;
#endif

int init_module()
{
printk("hello world\n";
printk("i have running in kernel module\n";
return 0;
}
int clearup_module()
{
printk("i will shut down myself in kernel module\n";  
这样就可以了

论坛徽章:
0
3 [报告]
发表于 2005-04-25 19:17 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

to Go_To_CU
你的意思是把#define MODVERSIONS 这个+上,是吧.我开始就试过了,
错误提示还是一样的
hello_mod.o: couldn't find the kernel version the module was compiled for

论坛徽章:
0
4 [报告]
发表于 2005-04-25 20:19 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

还修改了几个,你没看到吗?
编译:gcc -O2 -D__KERNEL__ -hello_mod.c -I/usr/src/linux/inlcude

论坛徽章:
0
5 [报告]
发表于 2005-04-25 21:01 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

原帖由 "Go_To_CU" 发表:
#include <linux/kernel.h>;
#include <linux/module.h>;
#if (CONFIG_MODVERSIONS==1 )
#define MODVERSIONS
#include <linux/modversions.h>;
#endif

int init_module()
{
print..........

    这个是你第一次的回复,难道我看错了?

gcc -O2 -D__KERNEL__  -hello_mod.c -I/usr/src/linux/include
    这个是你第二次的回复.是不是该是:
gcc -O2 -D__KERNEL__  -c hello_mod.c -I/usr/src/linux/include
    恕本人菜了,两种方法都不对,错误一样.
    再次求教!不搞定不罢休!

论坛徽章:
0
6 [报告]
发表于 2005-04-26 09:26 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

init_module函数里识return 0,cleanup_module不需要return 1;请把详细的错误贴上来,另外你有没有自己编译内核?

论坛徽章:
0
7 [报告]
发表于 2005-04-28 12:30 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

不好意思,这两天网络有问题,一直没上线,谢谢Go_To_CU   一直关注。
对与你的回复:
1 我觉得问题好像不在乎return
2 我没有自己编译内核

    我也觉得是编译时的参数问题,找了些资料,多是注重coding,对这个讲的不多。各位帮忙看看这个小小的demo,和大家平时的比较下,有哪里需要改的? 这是小弟第一次写,个位帮忙了。
   现在在win下,改后和改前的错误提示完全一样。哎,等下再贴一次吧。

论坛徽章:
0
8 [报告]
发表于 2005-04-29 08:55 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

/*
* File : hello_mod.c
* a simple module example
* date : 2005.4.25
*/
#include <linux/kernel.h>;
#include <linux/module.h>;
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>;
#endif

int init_module()
{
  printk("hello world\n";
  printk("i have running in kernel module\n";
  return 0;
}
int clearup_module()
{
  printk("i will shut down myself in kernel module\n";
  //return 1;
}
    以上就是我最后改的了...
    编译:gcc -O2 -D__KERNEL__  -c hello_mod.c -I/usr/src/linux/include通过.
    还是insmod hello_mod.o的时候出现错误:
[root@localhost kernel]# insmod hello_mod.o
hello_mod.o: couldn't find the kernel version the module was compiled for
    实在不知该如何解决了,请各位帮帮忙.

论坛徽章:
0
9 [报告]
发表于 2005-04-29 08:57 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

做个makefile 如下:
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC       := gcc
OBJS     := ${pasubst %.c, %.o, ${wildcard *.c}}

all: ${OBJS}

.PHONY: clean

clean:
<tab>;rm -rf *.o
<tab>;rm -rf *~

我试过了,一切ok!!           

论坛徽章:
0
10 [报告]
发表于 2005-04-29 09:03 |只看该作者

一个简单Linux内核模块遇到问题.帮帮忙

刚才没好好看,不好意思,你的程序有点问题!!!
1. init_module ....
... return 1; ------>; return 0; (否则会异常)

2. clearup_module.....
....      ------------->; 应该是cleanup_module 你写错了.现在应该 ok 了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP