module开发工程目录

来源:互联网 发布:怎么seo 编辑:程序博客网 时间:2024/06/05 08:33

1、目录组织结构如下,本文主要讨论几个问题:不同模块之间如何相互调用;如何使用多个源文件生成一个ko文件;采用多个子目录

2、模块通过EXPORT_SYMBOL导出函数,供其他模块使用.hello_.c

#include <linux/init.h>#include <linux/module.h>#include "common.h"static int hello_init(void){printk(KERN_ALERT "Hello ,modules world!\n");lib1();return 0;}static void hello_exit(void){printk(KERN_ALERT "Goodby,cruel world\n");}void func(void){printk("This is func\n");}MODULE_LICENSE("Dual BSD/GPL");module_init(hello_init);module_exit(hello_exit);EXPORT_SYMBOL(func);
然后在hello2.c中就可以直接使用了:

#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>//This function is define in module hellovoid func(void);int __init hello_init(void){printk("hello 2 !\n");func();return 0;}void __exit hello_exit(void){printk("hello 2 exit\n");}module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("Dual BSD/GPL");
3、使用多个源文件生成一个ko文件,详细参照Kbuild文档:

obj-m := hello.o#This will link hello_.o and common.o to hello.kohello-objs += hello_.o common.o

4、项目主(根)目录下的Makefile改为:

obj-m += hello/obj-m += hello2/obj-m += hello3/
make时将自动执行hello/目录下的Makefile文件


5、尝试在多处EXPORT_SYMBOL同一函数:在hello3.c中又定义一个名为func的函数,并导出:

echo "Kernel version: `uname -r`"Kernel version: 3.13.0-24-genericecho "kernel sources: "/lib/modules/`uname -r`/build""kernel sources: /lib/modules/3.13.0-24-generic/buildmake -C "/lib/modules/`uname -r`/build" SUBDIRS=`pwd` modulesmake[1]: Entering directory `/usr/src/linux-headers-3.13.0-24-generic'  CC [M]  /home/zhijian/work/fs/module_test/hello/hello_.o  CC [M]  /home/zhijian/work/fs/module_test/hello/common.o  LD [M]  /home/zhijian/work/fs/module_test/hello/hello.o  CC [M]  /home/zhijian/work/fs/module_test/hello2/hello2.o  CC [M]  /home/zhijian/work/fs/module_test/hello3/hello3.o  Building modules, stage 2.  MODPOST 3 modulesWARNING: /home/zhijian/work/fs/module_test/hello3/hello3: 'func' exported twice. Previous export was in /home/zhijian/work/fs/module_test/hello/hello.ko  CC      /home/zhijian/work/fs/module_test/hello/hello.mod.o  LD [M]  /home/zhijian/work/fs/module_test/hello/hello.ko  CC      /home/zhijian/work/fs/module_test/hello2/hello2.mod.o  LD [M]  /home/zhijian/work/fs/module_test/hello2/hello2.ko  CC      /home/zhijian/work/fs/module_test/hello3/hello3.mod.o  LD [M]  /home/zhijian/work/fs/module_test/hello3/hello3.komake[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic'
得到警告 'func'exported twice。



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 家长说你教的不好怎么办 小升初分班考试考砸了怎么办 老公不给老婆看病怎么办 孕妈妈涨奶严重怎么办 90岁老头尿不下尿怎么办 妻子要离婚丈夫不离怎么办 弟媳妇天天在家吵架怎么办 弟媳妇不和我说话怎么办 我想和弟媳妇做一次怎么办 老公对弟媳妇有非分之想怎么办 跟弟媳妇有矛盾怎么办 学生考试前不认真怎么办 有人雇凶要杀我怎么办 高考理综数学英语都没考好怎么办 母亲判刑孩子未成年无人监管怎么办 高三了数学30分怎么办 母猪发烧耳朵放血止不住了怎么办? 青春期孩子动手打父母该怎么办 20岁睡觉不老实怎么办 孕妇梦见钱掉了怎么办 小孩晚上睡觉鼻子塞怎么办 宝宝晚上睡觉鼻子塞怎么办 按摩后吹冷气发冷怎么办 碰到特别细心敏感的下属怎么办 睡觉压的肩膀疼怎么办 睡觉感觉被压住动弹不得怎么办 越想睡觉越睡不着怎么办 腿被裤子染黑了怎么办 肚子上的松皮怎么办 在公司天天背锅怎么办 职场老实背锅怎么办 三星a8充不了电怎么办 果6软件连不上网怎么办 孩子在幼儿园磕伤了怎么办 小孩在幼儿园摔骨折了怎么办 孩子在幼儿园摔骨折了怎么办 大腿被撞了很痛怎么办 马面褶子坏了怎么办 纱料衣服有褶怎么办 裙子如果后背那里小了怎么办 湖州耳朵鸣很严重怎么办