EXPORT_SYMBOL 符号导出实例

hello.c

#include <linux/module.h>  
#include <linux/init.h>  

static int num =10;  
int exportvalue=1234;
static void exportfunc(void)  //需要导出的函数
{  
    printk("exportfunc():num = %d;  exportvalue = %d\n",num,exportvalue);  
}  
static __init int hello_init(void)  
{  
    printk("hello_init \n");  
    return 0;  
}  
static __exit void hello_exit(void)  
{  
    printk("hello_exit \n");  
}  
EXPORT_SYMBOL(exportfunc);  
EXPORT_SYMBOL(exportvalue);
MODULE_LICENSE("GPL");  
module_init(hello_init);  
module_exit(hello_exit); 

callfile.c

#include <linux/module.h>  
  
extern void exportfunc(void);  //导出函数
extern int exportvalue;  //导出值
static int callfile_init(void)  
{  
    printk("callfile_init();exportvalue = %d, (exportvalue+2000) = %d\n",exportvalue,exportvalue+2000);  
    exportfunc();  
    return 0;  
}  
static void callfile_exit(void)  
{  
    printk("callfile_exit \n");  
}  
  
MODULE_LICENSE("GPL");  
  
module_init(callfile_init);  
module_exit(callfile_exit);

输出结果:

[root@FriendlyARM hello]# ls
Makefile        hello.c.bak     hello.mod.o
Module.symvers  hello.ko        hello.o
hello.c         hello.mod.c     modules.order
[root@FriendlyARM hello]# insmod hello.ko 
[  420.558519] hello_init 
[root@FriendlyARM hello]# cd ..
[root@FriendlyARM export_symbol]# ls
Makefile  callfile  hello     user
[root@FriendlyARM export_symbol]# cd callfile/
[root@FriendlyARM callfile]# ls
Makefile        callfile.c      callfile.mod.c  callfile.o
Module.symvers  callfile.ko     callfile.mod.o  modules.order
[root@FriendlyARM callfile]# insmod callfile.ko 
[  439.323566] callfile_init();exportvalue = 1234, (exportvalue+2000) = 3234
[  439.323630] exportfunc():num = 10;  exportvalue = 1234



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值