Results 1 to 6 of 6

Thread: Compile simple Kernel Module Problem

  1. #1
    Join Date
    Jul 2012
    Beans
    2

    Exclamation Compile simple Kernel Module Problem

    Hello, this is my first time here and i come with a problem i have been trying to figure out for 2 days. I just want to compile a simple "hello_world" kernel module.

    Here is my kernel module code (hello_module.c):
    Code:
    #include <linux/init.h>
    #include <linux/module.h>
    
    static int hello_init(void){
        printk (KERN_ALERT "Hello, I am a little module");     
        return 0;
    }
    
    static void hello_exit(void){
        printk (KERN_ALERT "Bye bye, nice to meet you");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);
    This is my Makefile:
    Code:
    obj-m += hello_module.o
    
    KDIR = /usr/src/linux-headers-3.2.0-26-generic
    
    all:
        $(MAKE) -C $(KDIR) SUBDIR=$(PWD)
    
    clean:
        rm -rf *.o *.ko *.mod *.symvers *.order
    The problem comes when i go to the directory and make, i get the following error:
    Code:
    make -C /usr/src/linux-headers-3.2.0-26-generic SUBDIR=/home/smfloris/Desktop/Modules
    make[1]: Entering directory `/usr/src/linux-headers-3.2.0-26-generic'
    make[2]: *** No rule to make target `arch/x86/tools/relocs.c', needed by `arch/x86/tools/relocs'.  Stop.
    make[1]: *** [archscripts] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-26-generic'
    make: *** [all] Error 2
    I couldn't find my problem anywhere, nor the solution. As a note, i've checked the headers and found that i have the latest version; I would also like to add that i installed Ubuntu through the Wubi installer.

    Any help is greatly appreciated,
    Flo.

    P.S. Please keep it simple, as i am still a beginner

  2. #2
    Join Date
    Jul 2012
    Beans
    2

    Lightbulb Re: Compile simple Kernel Module Problem

    So, i found a solution while browsing some threads; I removed the static keywords from the "hello_module.c" and modified the Makefile as such:

    Code:
    obj-m += hello_module.o
     
    all:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
     
    clean:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clea
    Last edited by SMFloris; July 15th, 2012 at 08:17 AM. Reason: added solution

  3. #3
    Join Date
    Sep 2012
    Beans
    1

    Re: Compile simple Kernel Module Problem

    i am having same issue tried de solution you recommend but no use plz help me

    Thamks in advance
    Error:-

    make -C /lib/modules/3.2.0-29-generic/build M= modules
    make[1]: Entering directory `/usr/src/linux-headers-3.2.0-29-generic'
    make[2]: *** No rule to make target `arch/x86/tools/relocs.c', needed by `arch/x86/tools/relocs'. Stop.
    make[1]: *** [archscripts] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic'
    make: *** [all] Error 2


    Make file

    obj-m += hello_module.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 help me////already wasted 5-6 hours already
    I am a beginner. So try to make the solution simple

  4. #4
    Join Date
    Oct 2012
    Beans
    1

    Re: Compile simple Kernel Module Problem

    Hi,
    I have the same problem as cityprince143 but not yet spent 5 hours with it. Please help.

  5. #5
    Join Date
    Mar 2013
    Beans
    1

    Re: Compile simple Kernel Module Problem

    I was facing same problem..getting the msg:

    No rule to make target `arch/x86/tools/relocs.c', needed by `arch/x86/tools/relocs'.

    The solution shown above didn't do me any good.

    Then I updated my linux source:
    $ sudo apt-get update
    $ sudo apt-get install linux-source.


    After doing this, I found a new folder in /usr/src: 'linux-source-3.2.0'
    Thus I had 4 folders now:
    linux-headers-3.2.0-32/ linux-headers-3.2.0-32-generic-pae/
    linux-headers-3.2.0-32-generic/ linux-source-3.2.0/

    The 'linux-source-3.2.0/' folder contained 'linux-source-3.2.0.tar.bz2'. I unzipped it and now the contents were:
    debian debian.master linux-source-3.2.0 linux-source-3.2.0.tar.bz2

    Now I just wrote one line in my Makefile: 'obj-m := first_driver.o' and executed the make command:
    sudo make -C /usr/src/linux-headers-3.2.0-32-generic-pae SUBDIRS=/home/isc/Desktop/first_driver.

    Voila!!! this generated the .ko file..

  6. #6
    Join Date
    Jan 2011
    Beans
    2

    Re: Compile simple Kernel Module Problem

    In the make file, just change M=$(PWD) into M=$(shell pwd)...

    Works like charm

Tags for this Thread

Bookmarks

Posting Permissions

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