读书人

编译模块 出现Entering directory `/u

发布时间: 2012-09-22 21:54:54 作者: rapoo

编译模块 出现Entering directory `/usr/src/kernels/2.6.9-11.EL-i686'是什么原因?
提示如下
[root@localhost Module_test2]# make
make -C /lib/modules/2.6.9-11.EL/build M=/root/home/Module_test2
make[1]: Entering directory `/usr/src/kernels/2.6.9-11.EL-i686'
LD /root/home/Module_test2/built-in.o
CC [M] /root/home/Module_test2/hello.o
Building modules, stage 2.
MODPOST
CC /root/home/Module_test2/hello.mod.o
LD [M] /root/home/Module_test2/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.9-11.EL-i686'
[root@localhost Module_test2]#

源代码如下
#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>

static int __init hello_init(void)
{
printk("Hello module init\n");
return 0;
}

static void __exit hello_exit(void)
{
printk("Hello module exit\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

Makefile如下
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif

请高手指点

[解决办法]
printk("Hello module init\n");

修改为:
printk(KERN_ALERT "Hello module init\n");
试试..
[解决办法]
如果要看到“Hello module exit”
就必须运行

#rmmod hello.ko
或者
#rmmod hello
[解决办法]
这提示信息不是成功的标志吗????

读书人网 >UNIXLINUX

热点推荐