Find the answer to your Linux question:
Results 1 to 6 of 6
Hello everyone, I am writing a very simple kernel module that is available on the net. But while compiling it I am getting the error for include files. Can anyone ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    3

    Smile Kernel Module


    Hello everyone,
    I am writing a very simple kernel module that is available on the net.
    But while compiling it I am getting the error for include files.

    Can anyone please tell me what is the procedure for include files for kernel modules.

    It would be really helpful if I get an example or a link I can get to learn about include files and kernel module programming starting from basics.

  2. #2
    Just Joined!
    Join Date
    Mar 2010
    Posts
    3

    Smile

    The Module I got only have printk in the init_module() and that in cleanup_module().

    It has a include file named uaccess.h
    It is not getting this file.
    I dont know where exactly the kernel module needs its include files.
    Is there any specific location.

    I am compiling it using gcc.
    and then using a Makefile for making a .ko .
    Which I suppose then will be inserted as a module using "insmod"
    and removed using "rmmod"

    If there is any other way to do it please tell me.

    I am reading Linux Kernel Module Programming .pdf O'reilly 2nd edition.

  3. #3
    Just Joined!
    Join Date
    Mar 2010
    Posts
    3
    the code looks something like this
    I dont know why it requires that uaccess.h

    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/uaccess.h>

    int init_module(void)
    {
    printk(KERN_INFO "init_module() called\n");
    return 0;
    }

    void cleanup_module(void)
    {
    printk(KERN_INFO "cleanup_module() called\n");
    }

    I tried to locate uaccess.h but not in linux named folder




    Makefile looks like this

    obj-m += hello.o

    all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Could you please use code tags so that we can see if the formating of your make file is correct..

    Also if you open a terminal and su root and type

    cd /lib/modules/$(uname -r)/build

    What do you get?
    Make mine Arch Linux

  6. #5
    Just Joined!
    Join Date
    Oct 2009
    Posts
    85
    Do you have the linux source in the given folder ?????

  7. #6
    Just Joined! saurabh.nigam's Avatar
    Join Date
    Sep 2008
    Location
    Indiyah!
    Posts
    15
    here is the MAkefile example(pls notice the usage of tab if you have provided 8 spaces that would be wrong)
    Code:
    obj-m += usb-skeleton.o
    
    all:
    <tab>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    <tab>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    save it & then run
    Code:
    #make
    try compiling your code without writing include<uaccess.h> line this could be a user defined header by the author

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •