Linking kernel module with a static lib

女生的网名这么多〃 提交于 2019-11-28 10:32:59

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

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

You're overriding the default my_prog-objs, which is just my_prog.o. Instead of replacing the contents with the library, add the library to the default:

my_prog-objs := my_prog.o some/path/lib.a

Hopefully you're not trying to link against a general userspace library... that won't work at all in kernelspace.

You must create a synthetic name as well as the source file and it's object name. You can not use my_prog.o directly as there are rules to make it from source. Here is an sample,

 obj-m += full.o
 full-src := my_prog.c
 full-objs := $(full-src:.c=.o) lib.o # yes, make it an object.

Libraries are only supported from some special directories. Your object should be named lib.o_shipped and placed in the same directory. See: item 11 under TODOnote. So, you need to take the external library and provide it locally as a shipped version. You need two object files; one is your compiled 'C' code/driver and the other is it linked together with the library.

Note: I am being facetious; it has a TODO to document this feature.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!