I am trying to compile my kernel module.
The .c file name is file1.c
, but I need the .ko file name to be mod1.ko
.
How can I do that?
My current makefile:
obj-m := mod1.o
KDIR :=/lib/modules/$(shell uname -r)/build
PDW := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PDW) modules
clean:
$(MAKE) -C $(KDIR) M=$(PDW) clean
You should change your first line to something like this:
obj-m += module_name.o
module_name-y := file1.o
Where module_name
is the module file name (in this example the output will be module_name.ko
) and it will be build from file1.c
. You can add more than one source file to the 2nd line, so it could be:
module_name-y := file1.o file2.o file3.o
In this case module_name.ko
will be build from file1.c
, file2.c
and file3.c
.
You should read this document if you want to fully understand Linux kernel makefiles. Your problem is described somewhere around line 190.
The solution looks like this:
obj-m += mod1.o
mod1-objs := file1.o
KBUILD_CPPFLAGS += -I$(PWD)/
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With