error: stdio.h: No such file or directory error during make

前端 未结 3 682
说谎
说谎 2020-12-30 15:56

I\'m trying to compile the following program in Ubuntu. But I keep getting the error: \"stdio.h: No such file or directory\" error.

#include 
         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-30 16:11

    The problem is you can't use printf() and stdio.h inside the kernel, and you don't use a main() function either. You need printk() and module.h

    #include  /* Needed by all modules */
    #include 
    
    int init_module(void)
    {
        printk(KERN_INFO "Hello world\n");
    
        return 0;
    }
    

    You should also have a exit()/cleanup() type function for when it unloads.

    void clean_module(void)
    {
        printk(KERN_INFO "Cleaning and exiting\n");
    }
    

    Then load the functions for the module:

    module_init(init_module);
    module_exit(clean_module);
    

提交回复
热议问题