[Click] Click Kernel Packages and Library Linking . . .

John Russell Lane johnrlane at gmail.com
Thu Oct 7 22:31:40 EDT 2010


Hello!

I have a question related to Click package building, which I haven't
seen on the mailing list or FAQ:

Is there a well-accepted method for getting static, kernel-ready
libraries linked to a Click kernel module?

Background:

I have a Click package (we'll call it "mypackage") which, for
userlevel Click, I link with with an external library (call it
"libmylib.so").  To tell Click that the external library is required,
I use something like ELEMENT_LIBS("-L ../mylib -lmylib") in one or
more of my Click package source files; all builds quite nicely and
links at runtime.

However, I'd like to move part of this into the kernel (i.e., build
"mypackage.ko").  I modified my the "mylib" source to add precisely
the same compile options Click adds for building source files (i.e.,
it basically does a make in the Linux kernel source tree for a
non-existent source file, has make dump the options used, parses them
via sed and adds them to the build).  I then built an ar archive
library (call it "libmylib.a") out of the subset of source files from
"mylib" which I've modified to run in the Linux kernel.

Now, initially, I thought there might be an easy way to get this
static library ("libmylib.a") linked with my Click package
("mypackage.ko"), but ELEMENT_LIBS definitely seems to be a
userlevel-only option and I haven't seen anything in the docs related
to getting external libraries linked into Click-built kernel modules.

For the moment, what I'm doing is having Click build "mypackage.ko",
rerunning the final linker call to include my "-L ../mylib -lmylib"
and then installing.  This builds, loads fine (via click-install) and
is working for the moment, but I'm hoping there's a more automated
method for doing this.  Ideally, something like an ELEMENT_KLIBS might
exist to add such libraries to the final linker call.  One option is
to fully integrate the "mylib" source into the "mypackage" source, but
since they're maintained separately, this is not really desirable.  A
similar option is to create symlinks in the "mypackage" source to the
"mylib" source files.  But I'm hoping there's something that can be
more easily maintained.

Has anyone else run into this issue?  Any suggestions, workarounds or
solutions would be greatly appreciated.

Thanks!

jrl.


More information about the click mailing list