Kernel Programming

Shrikar archak shrikar84 at gmail.com
Tue Mar 27 06:49:09 UTC 2007


Hi ,
I am a newbie to kernel programming and trying out some simple examples
given in a tutorial
the program is given below

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>
int init_module(void)
{
     printk(KERN_INFO "Hello world 1.\n");
    /*
    * A non 0 return means init_module failed; module can't be loaded.
    */
    return 0;
}
void cleanup_module(void)
{
                printk(KERN_INFO "Goodbye world 1.\n");
}

============================================
I get the following error when i try to compile
I have installed the kernel headers as well


shrikar at shrikar-desktop:~/kernel-programming$  gcc -D__KERNEL__  -DMODULE
-DLINUX -Wall -c hello1.c
In file included from /usr/include/linux/sched.h:16,
                 from /usr/include/linux/module.h:9,
                 from hello1.c:1:
/usr/include/linux/signal.h:2:2: warning: #warning "You should include <
signal.h>. This time I will do it for you."
In file included from /usr/include/linux/resource.h:4,
                 from /usr/include/linux/sched.h:79,
                 from /usr/include/linux/module.h:9,
                 from hello1.c:1:
/usr/include/linux/time.h:9: error: redefinition of 'struct timespec'
/usr/include/linux/time.h:15: error: redefinition of 'struct timeval'
/usr/include/linux/time.h:20: error: redefinition of 'struct timezone'
/usr/include/linux/time.h:47: error: redefinition of 'struct itimerval'
In file included from hello1.c:1:
/usr/include/linux/module.h:41: error: field 'attr' has incomplete type
/usr/include/linux/module.h:49: error: field 'kobj' has incomplete type
hello1.c: In function 'init_module':
hello1.c:6: warning: implicit declaration of function 'printk'
hello1.c:6: error: 'KERN_INFO' undeclared (first use in this function)
hello1.c:6: error: (Each undeclared identifier is reported only once
hello1.c:6: error: for each function it appears in.)
hello1.c:6: error: syntax error before string constant
hello1.c: In function 'cleanup_module':
hello1.c:14: error: 'KERN_INFO' undeclared (first use in this function)
hello1.c:14: error: syntax error before string constant


Thanks in advance
Shrikar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20070327/3793988e/attachment.html>


More information about the ubuntu-users mailing list