Arch Linux - Custom Kernel Module Compiling with 'undefined reference' Error During Build
I'm reviewing some code and I'm performance testing and I need help solving I'm optimizing some code but I'm optimizing some code but I'm sure I'm missing something obvious here, but I'm trying to compile a custom kernel module on Arch Linux with kernel version 6.1.12, but I'm running into an 'undefined reference' error during the build process..... I'm following a tutorial that outlines the process for creating a simple character device, but when I run `make`, I get the following error: ``` make -C /lib/modules/6.1.12-arch1-1/build M=$(pwd) modules make[1]: Entering directory '/usr/lib/modules/6.1.12-arch1-1/build' CC [M] /home/user/my_module/my_module.o /home/user/my_module/my_module.c: In function 'my_open': /home/user/my_module/my_module.c:21:5: error: 'struct file_operations' has no member named 'open' .open = my_open, ^~~~~ /home/user/my_module/my_module.c: In function 'my_read': /home/user/my_module/my_module.c:34:5: error: 'struct file_operations' has no member named 'read' .read = my_read, ^~~~~ make[1]: *** [Makefile:20: /home/user/my_module/my_module.o] Error 1 make[1]: Leaving directory '/usr/lib/modules/6.1.12-arch1-1/build' make: *** [Makefile:8: all] Error 2 ``` I've checked the kernel source and noticed that the `file_operations` structure has changed in this version of the kernel. I updated my module code to reflect the new structure: ```c #include <linux/module.h> #include <linux/fs.h> static int my_open(struct inode *inode, struct file *file) { return 0; } static ssize_t my_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { return 0; } static struct file_operations my_fops = { .owner = THIS_MODULE, }; static int __init my_module_init(void) { register_chrdev(0, "my_device", &my_fops); return 0; } static void __exit my_module_exit(void) { unregister_chrdev(0, "my_device"); } module_init(my_module_init); module_exit(my_module_exit); MODULE_LICENSE("GPL"); ``` Despite these changes, I still encounter the same errors related to the `file_operations` structure. I've also tried adding `.read = my_read,` and `.open = my_open,` back into the `file_operations` struct, but that leads to more undefined reference errors. I suspect that I might need to adjust my build configuration or include additional headers, but I'm not entirely sure what the next steps should be. Has anyone successfully compiled a character device module with the latest kernel changes? What should I check next? I'm working in a Ubuntu 22.04 environment. Hoping someone can shed some light on this. Is this even possible? I'd be grateful for any help. I've been using C for about a year now. Hoping someone can shed some light on this. I'm working with C in a Docker container on Ubuntu 20.04.