Linux/module.h:no such file or directory kernel module compilation process

Source: Internet
Author: User
Tags dmesg

1. Missing Linux kernel header file

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 your should use the kernel headers, the match the kernel you is running.

2. Kernel Module Compilation process Ubuntu

Source:

**/*source file name is BASIC.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 file

/*at first type on ur terminal that $ ( UNAME-R) then u'll get the version. That was using on the UR system */

obj-m + = BASIC.O

all:

$ (Make)-C $ (Kdir) subdirs=$ (PWD) Modules

RM-RF *.o *.ko *.mod.* *.symvers *.order

Kernel modules run:

$sudo Insmode Basic.ko

$DMESG ==> u'll get the output

$sudo Rmmod Basic.ko

$dmesg

Reference Links:

Http://stackoverflow.com/questions/16919512/linux-module-h-no-such-file-or-directory

Linux/module.h:no such file or directory kernel module compilation process

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.