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/