在centos 6上的helloworld 模块测试

来源:互联网 发布:电信运营商网络架构 编辑:程序博客网 时间:2024/05/17 23:57
[root@localhost test]# lshelloworld.c  Makefile[root@localhost test]# makemake -C /lib/modules/2.6.32-71.29.1.el6.i686/build M=/home/android/test modulesmake[1]: Entering directory `/usr/src/kernels/2.6.32-71.29.1.el6.i686'  CC [M]  /home/android/test/helloworld.o  Building modules, stage 2.  MODPOST 1 modules  CC      /home/android/test/helloworld.mod.o  LD [M]  /home/android/test/helloworld.ko.unsigned  NO SIGN [M] /home/android/test/helloworld.komake[1]: Leaving directory `/usr/src/kernels/2.6.32-71.29.1.el6.i686'[root@localhost test]# lshelloworld.c            helloworld.mod.c  Makefilehelloworld.ko           helloworld.mod.o  modules.orderhelloworld.ko.unsigned  helloworld.o      Module.symvers[root@localhost test]# insmod helloworld.koinsmod: error inserting 'helloworld.ko': -1 File exists[root@localhost test]# rmmod helloworld.ko[root@localhost test]# lshelloworld.c            helloworld.mod.c  Makefilehelloworld.ko           helloworld.mod.o  modules.orderhelloworld.ko.unsigned  helloworld.o      Module.symvers[root@localhost test]# insmod helloworld.ko[root@localhost test]# modinfo helloworld.kofilename:       helloworld.koauthor:         yuanweilicense:        GPLsrcversion:     E074EFF1EF4BF929639B50Ddepends:vermagic:       2.6.32-71.29.1.el6.i686 SMP mod_unload modversions 686[root@localhost test]#

附上 helloworld 源码和Makefile

#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>static int __init hellokernel_init(void){        printk(KERN_INFO "Hello kernel!\n");        return 0;}static void __exit hellokernel_exit(void){        printk(KERN_INFO "Exit kernel!\n");}module_init(hellokernel_init);module_exit(hellokernel_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("yuanwei");~~~~

obj-m := helloworld.oPWD       := $(shell pwd)all:        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modulesclean:        rm -rf *.o *~ core .*.cmd *.mod.c ./tmp_version *.ko.* modules.* Module.*


如果是CentOS 平台。需要安装kernel头文件

需要用YUM安装

[root@localhost test]# yum install kernel-devel
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * base: data.nicehosting.co.kr
 * extras: data.nicehosting.co.kr
 * updates: data.nicehosting.co.kr
Setting up Install Process
Package kernel-devel-2.6.32-71.29.1.el6.i686 already installed and latest version
Nothing to do



原创粉丝点击