Re: linking static library to generate LKM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jinu M. wrote:
Hi All,

I want to know how to link object files (.o) to a static library (.a)
and generate Loadable Kernel Module. Any pointers to examples demonstrating this should be of great help.


Here is what I do now.

I have three source files say x.c, y.c and z.c

I compile x.c to generate static library libx.a using the following command.

# ar -r libx.a x.c

Now I compile y.c and z.c to generate x.o and y.o

# cc -DMODULE -D__KERNEL__ -I/usr/src/linux/include -O2 -c -o y.o y.c # cc -DMODULE -D__KERNEL__ -I/usr/src/linux/include -O2 -c -o z.o z.c

Now as the final linking step I do this

# ld -r -o lkm.o y.o z.o -lx -L.

But when I try to load lkm.o I get unresolved symbol errors for the functions which are in x.c. I guess there is something wrong with linking procedure I use to generate the lkm.o

Please help me fix this.

Thanks,
-Jinu


-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/



Hi,


The problem is that u can't use your library in kernel mode. With your lkm, u can only use the functions inside the kernel. It's because the adress spaces are different in user and in kernel mode.
But u can create a "pseudo library" : u can compile ur library to a lkm. When the lkm "library" will be loaded, ur others lkm will be able to use the functions of the "library".
But remember that u can't use library in kernel mode (so in lkm) :)


Ciao


-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux