Find the answer to your Linux question:
Results 1 to 7 of 7
Hi Everyone, This is the hello world kernel module: #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk(KERN_INFO "Hello world.\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world\n"); } and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    5

    Hello world Module


    Hi Everyone,

    This is the hello world kernel module:
    #include <linux/module.h>
    #include <linux/kernel.h>
    int init_module(void)
    {
    printk(KERN_INFO "Hello world.\n");
    return 0;
    }
    void cleanup_module(void)
    {
    printk(KERN_INFO "Goodbye world\n");
    }

    and this is the make file

    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

    At the command prompt i type make and this is what I am getting:

    make -C /lib/modues/2.6.24-16-generic/build M=/home/louisemodules
    make[1]: Entering directory 'usr/src/linux-headers-2.6.24-16-generic
    make: *** [all] Error 2
    mkdir: cannot create directory home/louisemodules: permission denied
    scripts /Makefile.build:41: home/louisemodules/Makefile: No such file or
    directory
    make[2]: *** No rule to make target /home/louisemodules/Makefile. Stop
    make[1]:***[_module_/home/louisemodules] Error 2
    make[1]: Leaving directory /usr/src/linux-headers-2.6.24-16-generic
    make: *** [all] Error 2

    Please help me,

    Thanks

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Did you install the kernel-header and kernel-devel files?
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    5

    Did you install the kernel-header and kernel-devel files?

    Hi there,

    Thanks for getting back to me. I know that I have the header files, is there a command that I can type to check for deval files? Looking at the output when I run make, it seems to be opening the header files, but seems to have a problem making the directory for the module.

    Thanks

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Try logging in as root
    Make mine Arch Linux

  5. #5
    Just Joined!
    Join Date
    Dec 2009
    Posts
    5
    Hi Gerard,

    I tried that, but I am still getting the same error message. Have you any other suggestions?
    Thanks

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    The only other thing I can think of...Is your Makefile formatted correctly

    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
    where each make line is <TAB> in
    Make mine Arch Linux

  7. #7
    Just Joined!
    Join Date
    Jul 2009
    Posts
    49

    kernel module compile problems...

    I tried your code on my machine here. I ran into an issue with where your make file is expecting to find your kernel source. This pointed out to me that we really need to know which distro you are compiling on. I use openSuSE which really used the /lib/module/`uname -r`/source directory rather than the /lib/module/`uname -r`/build directory. This is easily fixed with a symbolic link (which did exist but was pointing to the wrong place.. better go annoy the openSuSE people about that!).

    So, which distro are you compiling on?

    Cheers!!

Posting Permissions

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