Hello i am trying to compile my first kernel module but i am receiving an error message. The hello.c program for my module is shown below:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void){
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
My makefile is the following:
obj-m := hello.o
KDIR := /lib/modules/4.19.94-ti-r42/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD)
I also want to mention that i tried to replace M=$(PWD)
with SUBDIRS=$(PWD)
but i still received the same error. When i run my make file i receive the following error message:
debian@beaglebone:~/LDD-3$ make
make -C /lib/modules/4.19.94-ti-r42/build M=/home/debian/LDD-3
make[1]: Entering directory '/usr/src/linux-headers-4.19.94-ti-r42'
scripts/Makefile.build:45: /home/debian/LDD-3/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/debian/LDD-3/Makefile'. Stop.
make[1]: *** [Makefile:1522: _module_/home/debian/LDD-3] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.19.94-ti-r42'
make: *** [makefile:6: default] Error 2
Does anyone know what i may be doing wrong? Thank you.
You named your makefile makefile
, as we can see from this message:
make: *** [makefile:6: default] Error 2
The kernel build system expects your makefile to be named Makefile
, as can be seen in this message:
scripts/Makefile.build:45: /home/debian/LDD-3/Makefile: No such file or directory
So I suggest you use:
mv makefile Makefile
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments