How to link a static library to a kernel module
I am a linux newbie and i want to know whether it is possible to link a static library to a kernal module. if so any sample piece of code (mainly the inclusion of that paticular .a file in make file )is very much thankful. Thanks in advance for u r help.
Yes, this should be possible, provided your library archive doesnít depend on any external symbols (e.g., no C-library dependence). There are two things meant by your question, and both are possible. The first is: can you have multiple source files linked to form one single loadable kernel module, much as they can form an archive or executable in userspace? The second is: suppose you have a precompiled (for the target arch) library archive making use of no external symbols. Can you use that object code in a kernel module without the source code? The answer to both is yes, as I will show in this example.
Suppose I want to make a module which will eventually be called foo.ko. The logic is complicated enough to be separated into two separate source files: bar.c and baz.c (this addresses the first question). Additionally, there is a precompiled library filled with symbols referenced by bar.c or baz.c. This is named qux.a (this addresses the second question). Then there is a Makefile to tie it all together (this is the file I will show you). All four of these files live in the same directory (for simplicity), which happens to be somewhere outside the kernel source tree (also for simplicity).
The Makefile might go something like this:
P.S., you can read more about using Makefiles with the kbuild system here.
|All times are GMT -5. The time now is 03:01 PM.|