linux/module.h: No such file or directory 內核模塊編譯過程


1、缺少Linux kernel頭文件

To install just the headers in Ubuntu:

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

To install the entire Linux kernel source in Ubuntu:

sudo apt-get install linux-source

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

2、內核模塊編譯過程ubuntu

源碼 hello.c :

 

#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文件

 

# 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

 

內核模塊運行:

 

$ 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM