Find the answer to your Linux question:
Results 1 to 5 of 5
Hello friends! I'm following the guide "The linux kernel module programming guide". I'm trying with the hello world mode, wich code is this: Code: #include <linux/module.h> #include <linux/kernel.h> int init_module(void) ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104

    [SOLVED] hello world module problem


    Hello friends! I'm following the guide "The linux kernel module programming guide". I'm trying with the hello world mode, wich code is this:

    Code:
    #include <linux/module.h>
    #include <linux/kernel.h>
    int init_module(void)
    {
      printk(KERN_INFO "Hello world 1.\n");
    
    return 0;
    }
    void cleanup_module(void)
    {
      printk(KERN_INFO "Goodbye world 1.\n");
    }
    The original make file in the guide is wrong. This is the code
    Code:
    obj−m += hello−1.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
    Which tells "Nothing to be done for all"

    So i found this makefile in the web:
    Code:
    obj-m += hello.o
    
    KDIR    := /lib/modules/2.6.32-27-generic/build
    PWD    := $(/home/jesus/pruebas/c/)
    
    default:
    	make -C $(KDIR) SUBDIRS=$(PWD) modules
    Which trhows this error message:

    Code:
    make -C /lib/modules/2.6.32-27-generic/build SUBDIRS= modules
    make[1]: se ingresa al directorio `/usr/src/linux-headers-2.6.32-27-generic'
      CHK     include/linux/version.h
      CHK     include/linux/utsrelease.h
      SYMLINK include/asm -> include/asm-x86
    make[2]: *** No hay ninguna regla para construir el objetivo `kernel/bounds.c', necesario para `kernel/bounds.s'.  Alto.
    make[1]: *** [prepare0] Error 2
    make[1]: se sale del directorio `/usr/src/linux-headers-2.6.32-27-generic'
    make: *** [default] Error 2
    Please help!!!
    Many thanks!

  2. #2
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104
    I found the error for the first Makefile. After "all:" there must be a "tab" instead of spaces:

    Code:
    obj-m += hello.o
    all:
    	make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c modules
    clean:
    	make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c clean
    With this makefile, i get this error message:
    Code:
    make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c modules
    make[1]: se ingresa al directorio `/usr/src/linux-headers-2.6.32-27-generic'
    make[2]: *** No hay ninguna regla para construir el objetivo `/home/jesus/pruebas/c/hello.c', necesario para `/home/jesus/pruebas/c/hello.o'.  Alto.
    make[1]: *** [_module_/home/jesus/pruebas/c] Error 2
    make[1]: se sale del directorio `/usr/src/linux-headers-2.6.32-27-generic'
    make: *** [all] Error 2

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4
    Good day.
    I also had issue compiling hello world module.
    This helped in my case.
    first manually write your Makefile, dont copy and paste from tutorial.
    Actually daches ,and another characters are differ.

    obj-m , −C , −r

    The dache signs here copied from your post and are differ than ascii dash '-' .

    Second.
    I don't know much about kernel policy of compiling modules, but some modules
    requare Kbuild file, others dont.

    So try this way.

    Cut obj-m += hello.o string from your Makefile, create new Kbuild file
    in the same dir and save obj-m += hello.o string in Kbuild file and then compile.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4
    Good day.
    I also had issue compiling hello world module.
    This helped in my case.
    first manually write your Makefile, dont copy and paste from tutorial.
    Actually daches ,and another characters are differ.

    obj-m , −C , −r

    The dache signs here copied from your post and are differ than ascii dash '-' .

    Second.
    I don't know much about kernel policy of compiling modules, but some modules
    requare Kbuild file, others dont.

    So try this way.

    Cut obj-m += hello.o string from your Makefile, create new Kbuild file
    in the same dir and save obj-m += hello.o string in Kbuild file and then compile.

  6. #5
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104
    Hi heliks!! Many thanks!! This make file i have just found, works properly too!

    Code:
    ifeq ($(KERNELRELEASE),)
    
    # Assume the source tree is where the running kernel was built
    # You should set KERNELDIR in the environment if it's elsewhere
    KERNELDIR ?= /lib/modules/2.6.32-27-generic/build
    
    # The current directory is passed to sub-makes as argument
    PWD := /home/jesus/pruebas/module2/
    
    modules:
    	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
    
    modules_install:
    	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
    
    clean:
    	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
    
    .PHONY: modules modules_install clean
    
    else
    # called from kernel build system: just declare what our modules are
    	obj-m := hello.o
    	obj-m := hello2.o
    endif

Posting Permissions

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