Sample.c:
#include
#include
#include
//MODULE_LICENCE("GPL");
static int my_module_init(void)
{
printk(KERN_INFO "Module A Initialised!\n");
return 0;
}
static void my_module_exit(void)
{
printk(KERN_INFO "Module A Exiting!\n");
}
module_init(my_module_init);
module_exit(my_module_exit);
MODULE_LICENCE("GPL");
~
Makefile:
obj-m += sample.o
#KERN_DIR=/lib/modules/6.5.0-18-generic/build
KERN_DIR=/lib/modules/$(shell uname -r)/build
all:
make -C $(KERN_DIR) M=$(PWD) modules
clean:
make -C $(KERN_DIR) M=$(PWD) clean
help:
make -C $(KERN_DIR) M=$(PWD) help
sample.ko:sample.c
make -C $(KERN_DIR) M=$(PWD) modules
Ошибка:
root@Ubuntu18:/home/adminadmin/Exercises/sample# make
make -C /lib/modules/6.5.0-27-generic/build M=/home/adminadmin/Exercises/sample modules
make[1]: Entering directory '/usr/src/linux-headers-6.5.0-27-generic'
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
You are using: gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
CC [M] /home/adminadmin/Exercises/sample/sample.o
/home/adminadmin/Exercises/sample/sample.c:21:16: error: expected declaration specifiers or ‘...’ before string constant
21 | MODULE_LICENCE("GPL");
| ^~~~~
make[3]: *** [scripts/Makefile.build:251: /home/adminadmin/Exercises/sample/sample.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.5.0-27-generic/Makefile
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.5.0-27-generic'
make: *** [Makefile:6: all] Error 2
root@Ubuntu18:/home/adminadmin/Exercises/sample#
Подробнее здесь: https://stackoverflow.com/questions/783 ... aration-sp