Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I am new to linux kernel stuff. I tried to write up my first kernel program as the following: #include <linux/kernel.h> #include <linux/module.h> int init_module() { printk("Kernel speaking\n"); return ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2005
    Posts
    1

    imcomplete kernel.h


    Hi,
    I am new to linux kernel stuff.
    I tried to write up my first kernel program as the following:

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

    int init_module()
    {
    printk("Kernel speaking\n");
    return 0;
    }

    void cleanup_module()
    {
    printk("Short-lived program \n");
    }

    However when I compile, I got
    hello.c:6: warning: implicit declaration of function `printk'

    The prink is supposed to be defined in kernel.h.

    However the current kernel.h on my workstation is very short:
    #ifndef _LINUX_KERNEL_H
    #define _LINUX_KERNEL_H

    /*
    * 'kernel.h' contains some often-used function prototypes etc
    */


    #define SI_LOAD_SHIFT 16
    struct sysinfo {
    long uptime; /* Seconds since boot */
    unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
    unsigned long totalram; /* Total usable main memory size */
    unsigned long freeram; /* Available memory size */
    unsigned long sharedram; /* Amount of shared memory */
    unsigned long bufferram; /* Memory used by buffers */
    unsigned long totalswap; /* Total swap space size */
    unsigned long freeswap; /* swap space still available */
    unsigned short procs; /* Number of current processes */
    unsigned short pad; /* explicit padding for m68k */
    unsigned long totalhigh; /* Total high memory size */
    unsigned long freehigh; /* Available high memory size */
    unsigned int mem_unit; /* Memory unit size in bytes */
    char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
    };

    #endif

    Anyone has any ideas?
    Thanks

  2. #2
    Just Joined!
    Join Date
    Nov 2004
    Posts
    47
    try:

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

    int init_module()
    {
    printk("Kernel speaking\n");
    return 0;
    }

    void cleanup_module()
    {
    printk("Short-lived program \n");
    }

    module_init(init_module);
    module_exit(cleanup_module);

Posting Permissions

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