You practically cannot do that (linking a shared library into the kernel or some kernel module).
The kernel is conceptually a freestanding program (so does not know about low-level standard C functions like malloc
or fprintf
that your shared library is very likely to use). Kernel modules (*.ko
files) are specially built and are loaded by some special kernel code.
Also, user-land code (including libraries) are based upon system calls (listed in syscalls(2)), which are not available in kernel code (since the kernel is providing the system calls to processes running in user mode thru specific machinery).
You might consider having a user-land helper program communicating with the kernel (i.e. your kernel module), e.g. using netlink(7). Perhaps look also into systemd.
You probably should read more about Operating Systems and read Advanced Linux Programming to understand the user-land aspects.
BTW, as a rule of thumb, you should limit the amount of kernel code added to the system (and prefer working in user-land).