linux/module.h: No such file or directory 内核模块编译过程

一、缺乏Linux kernel头文件linux

To install just the headers in Ubuntu:shell

sudo apt-get install linux-headers-$(uname -r)

To install the entire Linux kernel source in Ubuntu:ubuntu

sudo apt-get install linux-source

Note that you should use the kernel headers that match the kernel you are running.spa

二、内核模块编译过程ubuntublog

源码 hello.c :ci

 

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

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT "Hello, world\n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

 

Makefile文件terminal

 

# at first type on ur terminal that $(uname -r) then u will get the version.. 
# that is using on ur system

obj-m += hello.o

KDIR =/usr/src/linux-headers-$(shell uname -r)

all:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
        rm -rf *.o *.ko *.mod.* *.symvers *.order

 

内核模块运行:get

 

$ sudo insmod hello.ko
$ dmesg           ==> u will get the output
$ sudo rmmod hello
$ dmesg

 

参考连接:http://stackoverflow.com/questions/16919512/linux-module-h-no-such-file-or-directory源码

相关文章
相关标签/搜索