Linux模块多个文件,linux – 具有多个文件的内核模块 – 未知...

作者尝试编译加载包含两个文件模块的系统,遇到了编译警告及模块加载失败的问题。其中一个模块无法找到定义在另一个模块中的函数。

你好stackoverflowers ?

在过去的几个小时里,我一直在尝试编译加载多个文件模块.编译发出奇怪的警告,模块无法加载.这是模块,Makefile,编译输出和dmesg.

标题:

// header.h

#ifndef _HEADER_H

#define _HEADER_H

void do_module_func(void);

void do_other_func(void);

#endif

‘main’模块文件:

//mymodule.c

#include

#include

#include "header.h"

void do_module_func(void)

{

printk(KERN_INFO "module_func

");

}

static int mymodule_init(void)

{

printk(KERN_INFO "Hello world

");

do_other_func();

return 0;

}

module_init(mymodule_init);

static void mymodule_exit(void)

{

printk(KERN_INFO "Goodbye, cruel world

");

}

module_exit(mymodule_exit);

MODULE_LICENSE("GPL")

其他c文件,它调用位于’main’模块中的do_module_func()

//other_file.c

#include "header.h"

#include

void do_other_func(void)

{

printk(KERN_INFO "other_func

");

do_module_func();

}

Makefile文件

//Makefile

obj-m := mymodule.o

mymodule-objs := other_file.o

CROSS:=arm-unknown-linux-gnueabi-

KERNEL:= ~/work/linux-davinci-2.6.38/

ARCH:=arm

PWD:=$(shell pwd)

all:

$(MAKE) CROSS_COMPILE=$(CROSS) ARCH=$(ARCH) -C $(KERNEL) M=$(PWD) modules

clean:

$(MAKE) CROSS_COMPILE=$(CROSS) ARCH=$(ARCH) -C $(KERNEL) M=$(PWD) clean

我正在编译,但我相信这应该不是问题.

输出:

make CROSS_COMPILE....

make[1]: Entering directory .../linux-davinci-2.6.38

CC [M] .../other_file.o

LD [M] .../mymodule.o

Building modules, stage 2.

MODPOST 1 modules

WARNING: "do_module_func" [.../mymodule.o] undefined!

CC .../mymodule.mod.o

LD [M] .../mymodule.ko

make[1]: Leaving directory .../linux-davinci-2.6.38

insmod输出:

无法插入’mymodule.ko’:模块中的未知符号或未知参数

dmesg的:

mymodule:未知符号do_mdule_func(错误0)

因此,模块编译(链接?)警告,模块不加载.

现在,我看到在make输出中,在编译other_file.c之后似乎存在链接尝试,但是在链接之前不应该还有mymodule.c的编译吗?

谢谢! ?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值