- 论坛徽章:
- 0
|
本帖最后由 zhycjh 于 2018-07-17 09:35 编辑
我在ubuntu1804上面,我先有一个最简单的hellomod.c文件
- #include <linux/init.h>
- #include <linux/module.h>
- static int __init hello_init(void) {
- printk(KERN_ALERT "Hello, world\n");
- return 0;
- }
- static void __exit hello_exit(void) {
- printk(KERN_ALERT "Goodbye, cruel world\n");
- }
- module_init(hello_init);
- module_exit(hello_exit);
复制代码 上面这个文件经过makefile编译是可以insmod的,没问题。 obj-m += hellomod.o
- KERNEL ?= /lib/modules/$(shell uname -r)/build
- all:
- make -C $(KERNEL) M=$(PWD) modules
- clean:
- make -C $(KERNEL) M=$(PWD) clean
复制代码
然后我增加一个mylist.c
- #include <linux/module.h>
- #include <linux/kernel.h>
- void doublelist_init(void){}
- void doublelist_exit(void){}
复制代码 随后修改hellomod.c
- #include <linux/init.h>
- #include <linux/module.h>
- MODULE_LICENSE("GPL");
- void doublelist_init(void);
- static int __init hello_init(void) {
- printk(KERN_ALERT "Hello, world\n");
- doublelist_init();
- return 0;
- }
- void doublelist_exit(void);
- static void __exit hello_exit(void) {
- doublelist_exit();
- printk(KERN_ALERT "Goodbye, cruel world\n");
- }
- module_init(hello_init);
- 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还是不行。
怎么解决呢?请大虾指点
|
|