照例写了个小小驱动测试程序帮忙看看!

keenboy 2004-10-14 10:53:01
/*test.c*/
#include <linux/module.h>
#include <linux/kernel.h>

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

int init_module()
{
printk("hello world!\n");
printd("I have running in a kernel mod@!!\n");
return 1;
}

int cleanup_module()
{
printk("I will shut down myself in kernel mod!\n");
return 0;
}

#a makefile for a module
CC=gcc
MODCFLAG= -Wall _DMODULE -D_KERNEL_ -DLinux test.o test.c /usr/include/linux/version.h

all:
$(CC) $(MODCFLAG)

#echo the module is complie completely
想请问:
1.make时就是通不过
2.这里的
#include <linux/module.h>
#include <linux/kernel.h>
#if CONFIG_MODVERSIONS==1
#include <linux/modversions.h>
#endif
能找到LINUX/MODULE.H吗?

...全文
159 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bifengxie 2004-10-18
  • 打赏
  • 举报
回复
我的机器是RedHat 9.0,我是这样用的:

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
然后用gcc`编译


gcc -Wall -g -O2 -DMODULE -D__KERNEL__ -I /usr/src/linux-2.4.20-8/include -c testm.c

再在中端下:
insmod testm.o
可能没有输出,最好在控制台模式下,即按Ctrl+Alt+F1进入控制台模式
然后输入用户密码
再运行insmod testm.o就可看到输出,最后运行rmmod test也可得到输出

最后的最后 按键Ctrl+Alt+F7返回X window模式
GOOD LUCK
winux0 2004-10-15
  • 打赏
  • 举报
回复
试试看这样编译
gcc -Wall -O2 -DMODULE -D__KERNEL__ -I /usr/src/linux/include -c testm.c -o testm.o

4,436

社区成员

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

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