QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2052|回复: 4

模块的问题

[复制链接]
发表于 2006-10-18 15:37:42 | 显示全部楼层 |阅读模式
在看linux设备驱动程序上的例子,大家看一下什么问题
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
printk(KERN_ALERT "hello,world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye,cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
上面是hello.c程序
下面是Makefile
obj-m := hello.o
KERNELDIR = /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
        rm -f hello.ko hello.mod.c hello.mod.o hello.o
编译通过了
make -C /lib/modules/2.6.9-22.EL/build M=/home/lynn/module modules
make[1]: Entering directory `/usr/src/kernels/2.6.9-22.EL-i686'
  Building modules, stage 2.
  MODPOST
make[1]: Leaving directory `/usr/src/kernels/2.6.9-22.EL-i686'

可是在:insmod ./hello.ko后没有输出:hello,world
又看书上说在/var/log/message里可能有,我看了也没有

Oct 15 15:02:32 srr00968 syslogd 1.4.1: restart.
Oct 15 15:02:32 srr00968 syslog: syslogd 启动 succeeded
Oct 15 15:02:32 srr00968 kernel: klogd 1.4.1, log source = /proc/kmsg started.
Oct 15 15:02:32 srr00968 kernel: Linux version 2.6.9-22.EL ([email protected]) (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1 Mon Sep 19 18:20:28 EDT 2005
....................

为什么没有输出啊?请大家帮忙分析一下了
 楼主| 发表于 2006-10-18 15:41:33 | 显示全部楼层
make后 的内容应该是下面这样的,上面的是我没有make clean,
make -C /lib/modules/2.6.9-22.EL/build M=/home/lynn/module modules
make[1]: Entering directory `/usr/src/kernels/2.6.9-22.EL-i686'
  CC [M]  /home/lynn/module/hello.o
  Building modules, stage 2.
  MODPOST
  CC      /home/lynn/module/hello.mod.o
  LD [M]  /home/lynn/module/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.9-22.EL-i686'
回复

使用道具 举报

 楼主| 发表于 2006-10-18 15:48:07 | 显示全部楼层
Module                  Size  Used by
hello                   1536  0
parport_pc             24577  1
lp                     12077  0
parport                37129  2 parport_pc,lp
autofs4                23237  0
i2c_dev                11329  0
i2c_core               22081  1 i2c_dev


lsmod后看到hello模快
回复

使用道具 举报

发表于 2006-10-27 09:48:47 | 显示全部楼层

HELLO WORLD 模块显示

按ctrl+alt+F1切换到控制台下,然后再插入模块,就可以看到有显示
回复

使用道具 举报

 楼主| 发表于 2006-10-28 15:27:29 | 显示全部楼层
谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-19 22:51 , Processed in 0.106938 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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