I am taking an OS class and we have an upcoming assignment involving Kernel modules. I'm reading Wiley OS text to prepare and they have the below code. I keep on getting an error that the header files are not found. I'm using arch linux and I tried pacman -S linux-headers to install them so I know they are there.I also tried including direct path to init.h but the modules reference other modules from linux/.. directory. How can solve this? I am thinking that maybe I have to edit the ycm_extra_conf.py file but I don't know what to do.

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

/* This function is called when the module is loaded. */
int simple init(void) {
    printk(KERN INFO "Loading Kernel Module∖n");
    return 0;

/* This function is called when the module is removed. */
void simple exit(void) {
    printk(KERN INFO "Removing Kernel Module∖n");

/* Macros for registering module entry and exit points. */
module init(simple init);
module exit(simple exit);
  • 2
    I am not sure what Vim can do to fix your build issue. First try to figure out how to compile this without vim so you know what flags you need. Once you know all the required build flags, you can setup YouCompleteMe Sep 18, 2019 at 7:17
  • I can find all the required header files by navigating to /usr/src/linux-5.2.14.arch2/include/linux/. It's just that each of these header files reference others under linux/ . Thus for example YCM gives #include<init.h> file not found errors. Also, let's say for instance i run vim init.h, I get file not found error for compiler.h even though it is in the same directory Sep 18, 2019 at 20:39
  • Does it help if you use set path+=/usr/src/linux-5.2.14.arch2/include, maybe from your Vimrc? See `:help 'path' for more details.
    – filbranden
    Sep 19, 2019 at 3:21
  • I no longer get errors on module.h and kernel.h but i still get file not found on init.h. Running ':echo &path' returns '.,/usr/include,,,/usr/lib/modules/5.2.14-arch2-1-ARCH/build/include/' (i set it in vimrc like you said). Also when i manually navigate fs I can see init.h so i know it's there Sep 19, 2019 at 4:40
  • Also i set path to /usr/lib/modules/5.2.14-arch2-1-ARCH/build/include/** and now i can when i do :find init.h i get file. However, i still have error file not found. Maybe YCM issue? Sep 19, 2019 at 5:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.