Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
hi guys i am try to write a small module which is loding is say hello ,when remove it will put the console am gone thats all .my code is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2005
    Posts
    4

    where can find printk ?


    hi guys
    i am try to write a small module which is loding is say hello ,when remove it will put the console am gone thats all .my code is not have mistake .when inserted and remove module no output inserted the console.i think that the module can not find printk function i am using Redhat 9.0 kernel 2.4.20.8 please can any body help to me.

    Also for Windows a lot of beckmark program exist but linux version is not to
    much.I want to learn my CPU type and other information.But Linux could not use Bios ınterrup so that low level programmer how can write their application .Which interrup or books or program u can tell me to read

  2. #2
    Just Joined!
    Join Date
    Dec 2004
    Posts
    4
    the message can be written in var/log/messages or like it.

  3. #3
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    Check /var/log/kernel or something similar for the printk messages. All logs go to /var/log (by default). If you're not finding it, then you may not have sysklogd running.

    As for system info, all you'd ever want to know is in the /proc filesystem. Just use 'cat' to access the info:

    Code:
    cat /proc/cpuinfo
    cat /proc/meminfo
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jan 2005
    Posts
    4

    but there is a problem ?

    my code is like that

    #define MODULE
    #include <linux/module.h>

    int init_module (void) /* Loads a module in the kernel */
    {
    printk("Hello kernel n");
    return 0;
    }

    void cleanup_module(void) /* Removes module from kernel */
    {
    printk("GoodBye Kerneln");
    }

    i am compiling
    gcc -Wall -c mykernel.c

    error is :
    kmodule.c: In function `init_module':
    kmodule.c:6: warning: implicit declaration of function `printk'
    kmodule.c:13:2: warning: no newline at end of file
    /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x1: In function `_start':
    ../sysdeps/i386/elf/start.S:77: undefined reference to `main'
    /tmp/ccYecLMt.o(.text+0xf): In function `init_module':
    : undefined reference to `printk'
    /tmp/ccYecLMt.o(.text+0x2c): In function `cleanup_module':
    : undefined reference to `printk'
    collect2: ld returned 1 exit status

    so that printk cannot be found how can i solve problem /var/log has not existed the output.

    w

    my second question i am know /proc file is kernel outputs but i wanna use kernel header and write my own code it means i didnt wantto read that file and make output.I will wait ur answers .thanks all.

  6. #5
    Linux Enthusiast puntmuts's Avatar
    Join Date
    Dec 2004
    Location
    Republic Banana
    Posts
    562
    I'm not a programmer, so maybe my reply will be totally nonsense

    But if i do a grep on the kernel headers in /usr/include/linux and /usr/include/asm I see some headers containing the printk command. My guess would be linux/kernel.h, but as stated I'm not a programmer

    The grep command I used was:
    Code:
    grep -l -R printk /usr/include/asm/*.h
    grep -l -R printk /usr/include/linux/*.h
    That will show you a list of all headers containing the string printk .
    I\'m so tired .....
    #200472

  7. #6
    Just Joined!
    Join Date
    Dec 2004
    Location
    Bangalore
    Posts
    15

    here u can find printk

    hi,

    1.
    I got this same error message once.

    ": undefined reference to `printk' "

    Your code tells that, u have not included the file "kernel.h" file

    # include <linux/kernel.h>

    This file contains the defines for symbols used in printk and the decleration of printk file is also present in that file.

    2.
    The warning u r getting:->

    "kmodule.c:6: warning: implicit declaration of function `printk' "

    is ok and that should not cause problem while inserting module.

    3.
    You compiled using:

    "gcc -Wall -c mykernel.c "

    Try compiling using

    gcc -Wall -c mykernel.c -o mykernel.o -D__KERNEL__
    -I /usr/include/linux/ -O2

    Here every option given has specific meaning:
    You can find their meaning from the tutorials available for kernel programming. I have not given that matter here because when u will read such a tutorial , u can find something extra and worth for u.

    a)
    If u # define __KERNEL__ as u have done #define MODULE then u don'
    t have to give this with -D.
    b)
    -I gives the path to search. because ur path may be different, so u can check the path were "include files" for linux are present( mainly kernel.h and module.h)

    U can make a "makefile" for doing module programming. It will help u when u will have lots of files and only some files need to be recompiled, at that time makefiles are the best u have at one's end.

  8. #7
    Just Joined!
    Join Date
    Apr 2006
    Posts
    1

    My program is not Working

    I use printk function in my program and compile with what option u specify
    But it not working. It gives linker error

    My code is
    # include <linux/kernel.h>

    main()
    {
    printk("welcome to all.\n");
    }

    With regards,
    Pethicmuthulingam S

  9. #8
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Try to compile your module with:

    obj-m += hello-1.o

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

    (from Linux Kernel Module Programming Guide)

    You need kernel.h and module.h for your module. If you are not going to do a module, you will not be able to test it (unless you merge your code with the linux source code).

    After this, you shouldn't see any error messages or linker warnings. It is assumed that your module will be linked against the kernel.

    Best regards

  10. #9
    Just Joined!
    Join Date
    May 2006
    Posts
    2
    Quote Originally Posted by cahmetdeniz
    my code is like that

    #define MODULE
    #include <linux/module.h>

    int init_module (void) /* Loads a module in the kernel */
    {
    printk("Hello kernel n");
    return 0;
    }

    void cleanup_module(void) /* Removes module from kernel */
    {
    printk("GoodBye Kerneln");
    }

    i am compiling
    gcc -Wall -c mykernel.c

    error is :
    kmodule.c: In function `init_module':
    kmodule.c:6: warning: implicit declaration of function `printk'
    kmodule.c:13:2: warning: no newline at end of file
    /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x1: In function `_start':
    ../sysdeps/i386/elf/start.S:77: undefined reference to `main'
    /tmp/ccYecLMt.o(.text+0xf): In function `init_module':
    : undefined reference to `printk'
    /tmp/ccYecLMt.o(.text+0x2c): In function `cleanup_module':
    : undefined reference to `printk'
    collect2: ld returned 1 exit status

    so that printk cannot be found how can i solve problem /var/log has not existed the output.

    w

    my second question i am know /proc file is kernel outputs but i wanna use kernel header and write my own code it means i didnt wantto read that file and make output.I will wait ur answers .thanks all.
    I have read that guide before, the .c file and Makefile didn't work in kernel 2.6.16. The following is a better guide:

    http://free-electrons.com/doc/embedd...nd_drivers.pdf

  11. #10
    Just Joined!
    Join Date
    Jan 2005
    Posts
    2

    Cool

    i think u r compiling it on 2.6 kernel
    :-
    check this makefile for your module just replace the line
    obj-m :- hello.o with your file name ..

    /*******************************************/
    ifneq ($(KERNELRELEASE),)
    obj-m := hello.o
    else

    KERNELDIR ?= /lib/modules/2.6.13.1/build/

    PWD := $(shell pwd)

    default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules


    clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
    endif

    this resolve my prob... let see further

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
  •