Ubuntu 15.10 (Kernel 4.2): makefile error in Hello kernel module

I tried for hours to create my first Hello World Kernel module, alas, to no avail. My simple C code (hello.c) and the makefile are in / Downloads on my system, if that should be important.

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 get when I try to build a kernel module by entering "make" (without quotes) 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 tried almost all the solutions and followed every suggestion regarding this problem that can be found on google. Nothing could solve my problem ... If anyone knows anything that I could try, I would be very grateful!

  • Should I move hello.c and makefile to / usr / src?
  • Are there any syntax errors in my files?
  • Should he say hello.c instead of hello.o in the makefile?
  • Ubuntu - ?
  • ...
+4
1

"makefile" "Makefile" ( M) , , - . :

make -C/lib/modules/4.2.0-16-generic/build M =/home/username/workspace/test/ make [1]: '/usr/src/linux-headers-4.2.0-16-generic' , 2. MODPOST 0 make [1]: '/usr/src/linux-headers-4.2.0-16-generic'

^^ , - makefile ! , hello.ko.

, ?

OMG!!!

Google dsf: Linux: modpost ( )

, , Makefile , , , ! ., , , . , Makefile pdf/-, , , dsf ?!

.

0

Source: https://habr.com/ru/post/1613540/


All Articles