Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Dear everybody. I'm currently using RedHat Enterprise Linux kernel 2.6, and i can not find those header file <linux/module.h>, <linux/init.h> for doing kernel module programming. Can anyone suggest me what ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    8

    Missing header file in Linux kernel 2.6


    Dear everybody. I'm currently using RedHat Enterprise Linux kernel 2.6, and i can not find those header file <linux/module.h>, <linux/init.h> for doing kernel module programming. Can anyone suggest me what to do ? Can i normally copy those files from another source and paste them in the specific directory ? If yes, can anyone share it ? Thank you very much.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try this link: (8.6. Preparing for Kernel Development)

    Fedora Project, sponsored by Red Hat

    Hope this helps....Gerard4143

    and welcome to the forums

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    8
    Thank Gerard for your warmly welcome as well as your reply,but really i have not solved this problem yet ....Beside, i have installed Linux Kernel 2.4 in my Laptop and try doing device driver development and i faced plenty of error even for the simplest "Hello world" module. All the make file and the code were absolutely correct but still can not be implemented. Is there any restriction when installing Linux Red Hat may cause those errors ? Can any expert give me some advices. Thank you very much.

    @Gerard : Are you really from Prince Edward Island in Canada ? I have heard about this island from the story of a novelist , sir Jack London when i was a child. If i do not mistake, Prince Edward island is a very cold place and near the North pole right ?

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Yes I'm from Prince Edward Island but its probably not the Prince Edward Island your refering to which I think is in or near the south pole...

    About your kernel module problem could you post the make file and the "hello world" kernel module so we could have a look...also could you post the result of uname -a

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Posts
    8
    Here is my code

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

    static int __init helo_init(void)
    {
    printk(KERN_INFO "Hello world . \n");
    return 0;
    }
    static void __exit hello_exit(void)
    {
    printk(KERN_INFO "Goodbye world. \n");
    }

    module_init(hello_init);
    module exit(hello_exit);


    And the Makefile :

    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

    Just simple like that, but even when i try to compile:
    gcc hello.c -o hello.o
    it still shows plenty of errors which is related to some others kernel headers ... Have i done any mistake while installing Linux ?

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Don't use "gcc hello.c -o hello.o" just use "make" and it will call your Makefile and compile your kernel modules.

    and "insmod hello.ko"
    and then "rmmod hello"

    and check the file /var/log/messages for your entries "hello world" and "goodbye world"
    note the messages should be at the end of the messages file...Hope this helps Gerard4341

  7. #7
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You did have some errors but after some minor corrections it did run on my system...heres the corrected code...note once you get the first module working the rest are easier...Gerard4143

    my system:
    Linux linux-u5bz 2.6.25.18-0.2-default #1 SMP 2008-10-21 16:30:26 +0200 x86_64 x86_64 x86_64 GNU/Linux

    Code:
    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
    Please note the spacing in the makefile...be sure to use tab space to move in the lines:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    and
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

    Code:
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    
    static int __init hello_init(void)
    {
    	printk(KERN_INFO "Hello world . \n");
    	return 0;
    }
    static void __exit hello_exit(void)
    {
    	printk(KERN_INFO "Goodbye world. \n");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);
    use make to compile the module
    then insmod hello.ko
    then rmmod hello

    the results should be in the file /var/log/messages

  8. #8
    Just Joined!
    Join Date
    Nov 2008
    Posts
    8
    I have already use "make" command before try "gcc hello.c -o hello.o" seperately but nothing had happened Gerard.
    Yes, there was a minor error due to spacing in my Makefile as you have mentionedabove, i have corrected it and recompile the modules, but those previous error still appear. It is like : KERN_INFO undeclared . I doubt very much, i think that there should be an error in my Linux installation. I used 2 PC, 1 with Linux kernel 2.4 and the rest with kernel 2.6. With the 2.6 one, i have installed it as a web server and the error of header missing came. The 2.4 i installed as the workstation and the error when compiling module came. Please help me out of this ...

  9. #9
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    Post

    Amore on your computer with kernel 2.6 you have to set up Linux to compile kernel modules. this web site will show you the steps

    "8.6. Preparing for Kernel Development"
    Fedora Project, sponsored by Red Hat

    Note:
    What I showed you above will only work on a system with a 2.6 kernel that has been prepared for kernel development...Hope this helps Gerard4143

    Note:
    Linux changed the process for kernel module compiling between kernels 2.4 and 2.6 so a make file for 2.6 will not work for 2.4 and visa and versa...

  10. #10
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    On your Linux 2.6 box try the add/remove software and query kernel-devel. you should be presented with some options for development packages(development package for building kernel modules to match the kernel - kernel-devel-2.6....) for building kernel modules...choose the one that matches your system and your problems should go away...Hope this Helps

Page 1 of 2 1 2 LastLast

Posting Permissions

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