I am using kernel 5.10.11 in KALI and I am trying to learn kernel module programming but I am unable to build the module. I have tried all the solutions given on the internet but they are not working for me, or I am doing it the wrong way.
Here is my c file
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int helloWorld_init(void)
{
printk(KERN_DEBUG "Hello World!\n");
return 0;
}
static void helloWorld_exit(void)
{
printk(KERN_DEBUG "Removing Module\n");
}
module_init(helloWorld_init);
module_exit(helloWorld_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mukul Mehar");
MODULE_DESCRIPTION("first kernel module");
And the Makefile:
obj-m += helloWorld.o
KDIR = /usr/src/linux-headers-5.10.11/
all:
make -C $(KDIR) M=$(shell pwd) modules
clean:
make -C $(KDIR) M=$(shell pwd) clean
The output which I am receiving is:
make -C /usr/src/linux-headers-5.10.11/ M=/home/mukul/Documents/Eudyptula/challenge-1 modules
make[1]: Entering directory '/usr/src/linux-headers-5.10.11'
make[2]: *** No rule to make target '/home/mukul/Documents/Eudyptula/challenge-1/helloWorld.o', needed by '/home/mukul/Documents/Eudyptula/challenge-1/helloWorld.mod'. Stop.
make[1]: *** [Makefile:1805: /home/mukul/Documents/Eudyptula/challenge-1] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.10.11'
make: *** [Makefile:7: all] Error 2