3

全部:

我有 2 个文件,module1.c 和 module2.c,其中包含第三个文件 big_module.c 所需的功能。我的 Makefile 抱怨找不到 module1.c 和 module2.c 中定义的函数。big_module.c 需要这些函数你能帮我定义我的 Makefile 以便它工作吗?

模块1.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <asm/uaccess.h>

int module1 (struct file *filp, struct vm_area_struct *vma)
{ return 0; }

int __init init_module1 (void)
{ return 0; }

void __exit cleanup_module1 (void)
{ }

模块2.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#include <asm/io.h>

unsigned long virt_addr;

int module2(struct file * filp, struct vm_area_struct * vma)
{ return 0; }

int __init init_module2 (void)
{ return 0; }

void __exit cleanup_module2 (void) { }

大模块.c

#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/vt_kern.h>
#include <linux/fs.h>

MODULE_DESCRIPTION("Example");
MODULE_AUTHOR("Your Name Here");
MODULE_LICENSE("GPL");
static int __init hello_init(void)
{
    init_module1();
    init_module2();
    return 0;
}

static void __exit hello_cleanup(void)
{
    cleanup_module1();
    cleanup_module2();
}

module_init(hello_init);
module_exit(hello_cleanup);

生成文件:

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

obj-m += big_module.o
obj-m += module1.o
obj-m += module2.o

modules:
        $(MAKE) -C $(KDIR) M=$(PWD) modules

错误:

>     uu@uu-VirtualBox:~/UCSC-Ext/LDDII/Assignment3/ASK$ sudo make
>     make -C /lib/modules/3.10.0uu/build M=/home/uu/UCSC-Ext/LDDII/Assignment3/ASK modules
>     make[1]: Entering directory `/usr/src/linux-3.10'
>       CC [M]  /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.o
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c: In function ‘hello_init’:
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c:14:2: error: implicit declaration of function ‘init_module1’
> [-Werror=implicit-function-declaration]
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c:15:2: error: implicit declaration of function ‘init_module2’
> [-Werror=implicit-function-declaration]
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c: In function ‘hello_cleanup’:
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c:21:2: error: implicit declaration of function ‘cleanup_module1’
> [-Werror=implicit-function-declaration]
>     /home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.c:22:2: error: implicit declaration of function ‘cleanup_module2’
> [-Werror=implicit-function-declaration]
>     cc1: some warnings being treated as errors
>     make[2]: *** [/home/uu/UCSC-Ext/LDDII/Assignment3/ASK/big_module.o] Error 1
>     make[1]: *** [_module_/home/uu/UCSC-Ext/LDDII/Assignment3/ASK] Error 2
>     make[1]: Leaving directory `/usr/src/linux-3.10'
>     make: *** [modules] Error 2
4

1 回答 1

2

全部:

我找到了我的问题的解决方案。它在 Makefile 中,应该如下所示:

生成文件

========================

KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd)

obj-m := big_module.o

big_module-objs := module1.o module2.o

模块:$(MAKE) -C $(KDIR) M=$(PWD) 模块

========================

于 2013-11-01T20:26:08.940 回答