免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 51154 | 回复: 0
打印 上一主题 下一主题

最简单的hellomod,引用另一个.ko文件就说Unknown symbol in module [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-07-17 09:34 |只看该作者 |倒序浏览
本帖最后由 zhycjh 于 2018-07-17 09:35 编辑

我在ubuntu1804上面,我先有一个最简单的hellomod.c文件
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. static int __init hello_init(void) {
  4.    printk(KERN_ALERT "Hello, world\n");
  5.     return 0;
  6. }
  7. static void __exit hello_exit(void) {
  8.    printk(KERN_ALERT "Goodbye, cruel world\n");
  9. }
  10. module_init(hello_init);
  11. module_exit(hello_exit);
复制代码
上面这个文件经过makefile编译是可以insmod的,没问题。  obj-m += hellomod.o
  1. KERNEL ?= /lib/modules/$(shell uname -r)/build
  2. all:
  3.          make -C $(KERNEL) M=$(PWD) modules
  4. clean:
  5.          make -C $(KERNEL) M=$(PWD) clean
复制代码

  然后我增加一个mylist.c

  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. void doublelist_init(void){}
  4. void doublelist_exit(void){}
复制代码
随后修改hellomod.c

  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. MODULE_LICENSE("GPL");
  4. void doublelist_init(void);
  5. static int __init hello_init(void) {
  6.        printk(KERN_ALERT "Hello, world\n");
  7.        doublelist_init();
  8.        return 0;
  9. }
  10. void doublelist_exit(void);
  11.   static void __exit hello_exit(void) {
  12.        doublelist_exit();
  13.        printk(KERN_ALERT "Goodbye, cruel world\n");
  14. }
  15. module_init(hello_init);
  16. module_exit(hello_exit);
复制代码

  
以及makefile:
  
obj-m += hellomod.o mylist.o
module-objs := mylist.o
  
编译没有问题,但是加载的时候就告诉我
  
sudo insmod hellomod.ko
insmod: ERROR: could not insert module hellomod.ko: Unknown symbol in module
  
我尝试sudo insmod mylist.ko是ok的,但是再sudo insmo hellomod.ko还是不行。
  
怎么解决呢?请大虾指点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP