|
⇤ ← Revision 1 as of 2006-04-24 15:33:46
Size: 756
Comment: new entry in the FAQ : howto compile a kernel module
|
Size: 1056
Comment: More links.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| You have to write a Makefile. The Makefile is a standard one and depends on the kernel version. | You have to write a Makefile. The Makefile is a standard one and depends on the kernel version. Do not try to make your own Makefile, use the Linux kernel infrastructure, as explained below. |
| Line 16: | Line 16: |
For more informations, see [http://lwn.net/images/pdf/LDD3/ch02.pdf Linux Device Drivers, Building and Running Modules], and [http://lwn.net/Articles/21823/ Driver porting: compiling external modules]. |
How do I compile a Linux kernel module?
You have to write a Makefile. The Makefile is a standard one and depends on the kernel version. Do not try to make your own Makefile, use the Linux kernel infrastructure, as explained below.
Standard Makefile for 2.6 kernels
obj-m := name_of_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) cleanFor more informations, see [http://lwn.net/images/pdf/LDD3/ch02.pdf Linux Device Drivers, Building and Running Modules], and [http://lwn.net/Articles/21823/ Driver porting: compiling external modules].
Standard Makefile for 2.4 (and <=) kernels
TARGET := module_name
INCLUDE := -I/lib/modules/`uname -r`/build/include
CFLAGS := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
CC := gcc
${TARGET}.o: ${TARGET}.c
$(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.cOnce the module is compiled, you can load it with the following command :
insmod module.[ko|o]