本文介绍了将内核模块与静态库链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将内核模块与外部静态库链接,如下所示:

I'm trying to link my kernel module with an external static lib, like this:

obj-m += my_prog.o
my_prog-objs := some/path/lib.a
# all the standard targets...

出于某种原因,上面的Makefile根本不编译my_prog.c,并且生成的模块不包含其代码.当然,如果我删除my_prog-objs行,则会编译my_prog.c.

For some reasone, the above Makefile doesn't compile my_prog.c at all, and the resulting module doesn't contain its code. Certainly, if I remove my_prog-objs line, my_prog.c gets compiled.

在Makefile中使用这种方法有什么问题?

What's wrong with such an approach in a Makefile?

推荐答案

创建my_prog-objs列表时,您告诉kbuild仅使用该列表中的目标文件. kbuild将不再编译my_prog.c,并且在my_prog-objs中包含my_prog.o会导致循环依赖.相反,您需要创建一个唯一的obj-m并将my_prog.o/path/lib.a都包括在其objs列表中.例如:

When you create the my_prog-objs list, you tell kbuild to use only the object files in that list. kbuild will no longer compile my_prog.c, and including my_prog.o in my_prog-objs results in a circular dependency. Instead, you need to create a unique obj-m and include both my_prog.o and /path/lib.a in its objs list. For example:

obj-m += foo.o
foo-objs += my_prog.o /path/lib.a

花了我大约2个小时来弄清楚为什么我的模块什么也不做!

Took me about 2 hours to figure out why my module was doing nothing!

这篇关于将内核模块与静态库链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 05:21