Click to See Complete Forum and Search --> : Linux Modules Programming!


jackyopensrc
06-12-2003, 06:07 PM
I have some errors messges during the compilation time.

Please give me some advises! Thanks a lot!

These are my Module codes :

#include<linux/module.h> /*Needed by all modules */
#include<linux/kernel.h> /*Needed for KERN_ALERT */
#define MODULE

int init_module(void)
{
printk("<1> Hello,World 1. \n");

/* A non 0 returns means init_module failed; module */
/* can't be loaded */


return 0;

}

void cleanup_module(void)
{
printk(KERN_ALERT "GoodBYE! \n");
}

Messages returned on my screen:

In file included from hello1.c:3:
/usr/include/linux/module.h:60: parse error before `atomic_t'
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:62: parse error before `}'
/usr/include/linux/module.h:62: warning: data definition has no type or storage class
/usr/include/linux/module.h:91: parse error before `}'
hello1.c: In function `cleanup_module':
hello1.c:21: `KERN_ALERT' undeclared (first use in this function)
hello1.c:21: (Each undeclared identifier is reported only once
hello1.c:21: for each function it appears in.)
hello1.c:21: parse error before string constant

:cool:

Stuka
06-13-2003, 01:48 PM
Haven't checked a recent version, but in the 2.4.5 version, KERN_ALERT is in linux/kernel.h, and the usage appears correct - there's a #define in kernel.h like so:
#define pr_debug(fmt, arg...)
printk(KERN_DEBUG fmt, ##arg)
Hey...have you tried putting the #define MODULE line above where you include <linux/module.h>? It probably affects definitions.

bwkaz
06-13-2003, 06:52 PM
Stuka is correct -- you NEED to define MODULES somewhere before you include any kernel header files. You can either do this in your .c file, or you can do it by passing -DMODULES to the gcc command line.

While you're at it, you should also be defining _KERNEL_ (or something very much like that).