<linux/init.h> and <linux/module.h> header files do not exist and so on how to solve the problem

Source: Internet
Author: User
Tags header linux

This problem is really handled for an afternoon, but also to download the latest kernel to compile, in fact, is completely unnecessary, because the Ubuntu system can directly download the new kernel.

You can find these kernel folders under the/usr/src/folder, such as my own system:

and the header file does not exist and so on problem how solves "width=" 574 "src=" Png/1006332b4-0.png "/>

When blogging, you use the 3.13.0-19 kernel.

Write a hello.c test file:

 1 #include <linux/kernel.h>/*needed by all modules*/
 2 #include <linux/module.h>/*needed for kern_* */
  3 #include <linux/init.h>/* Needed for the macros * *
 4 
 5 module_license ("GPL");
 6 
 7 static int year=2014;
 8 
 9 static int hello_init (void)
{one   printk (kern_warning "Hello kernel, it '%d!\n", year);
return   0; 
a static void Hello_exit (void)
{   printk ("Bye, kernel!\n"); 
/* Main module function*/
module_init (hello_init);
Module_exit (Hello_exit);

Then write a makefile file using the Kbuild standard:

1 obj-m: = hello.o
2 
3 All:
4     $ (make)-c/lib/modules/$ (shell uname-r)/build m=$ (PWD)
modules 5
  
   6 Clean:
7     
  

Obj-m: = NAME.O indicates that a module (-m) is compiled and the resulting NAME.O file is from the name.c file.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.