I have been trying for hours to create my first Hello World Kernel module, alas unsuccessfully. My simple C code (hello.c) and makefile are located in /Downloads on my system, if that should be of any importance.
hello.c
#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);
makefile
obj−m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
And this is the error message I'm receiving when I try to build the kernel module by entering "make" (without quotation marks) in the terminal:
make -C /lib/modules/4.2.0-16-generic/build
M=/home/username/workspace/test/Module modules make[1]:
Entering directory '/usr/src/linux-headers-4.2.0-16-generic'
scripts/Makefile.build:44:
/home/username/workspace/test/Module/Makefile: No such file or
directory make[2]: *** No rule to make target
'/home/username/workspace/test/Module/Makefile'. Stop.
Makefile:1398: recipe for target
'_module_/home/username/workspace/test/Module' failed make[1]:
*** [_module_/home/username/workspace/test/Module] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.2.0-16-generic'
makefile:4: recipe for target 'all' failed make: *** [all] Error 2
I have tried pretty much every single solution and have followed every suggestion regarding this problem that can be found on google. Nothing could solve my problem ... If anybody knows anything I could try, I would be very grateful!
- Should I move my hello.c and makefile to /usr/src?
- Are there any syntax errors in my files?
- Should it say hello.c instead of hello.o in the makefile?
- Might my Ubuntu be missing something?
- ...