Re: Small problem, Can anybody help me?

From: Erik Mouw
Date: Thu May 06 2004 - 09:30:20 EST


On Thu, May 06, 2004 at 07:31:56PM +0530, Srinivas G. wrote:
> I have written a small hello.c program in the Linux Kernel version
> 2.4.18-3.

Ancient kernel with lots of known bugs and security issues. You'd
rather upgrade.

> The code is as follows.
> -----------------------
>
>
> define MODULE

The idea is to put that definition on the gcc command line.

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

You're missing #include <linux/kernel.h>

> MODULE_LICENSE("GPL");
>
> int Test_init(void)
> {
> printk("<1> Hello World\n");

Use KERN_ALERT instead of "<1>". We have #defines for a reason: if we
change the definition tomorrow, your source will still work. So use:

printk(KERN_ALERT "Hello, world!\n");

> return 0;
> }
>
> void Test_cleanup(void)
> {
> printk("<1> Good bye\n");
> }
>
> module_init(Test_init);
> module_exit(Test_cleanup);
>
>
> I compiled it under same kernel version that is 2.4.18-3. It was showing
> the following errors.
>
> In file included from hello.c:2:
> /usr/include/linux/module.h:60: parse error before `atomic_t'
^^^^^^^^^^^^
You're compiling against libc headers instead of kernel headers. See:

http://www.kernelnewbies.org/faq/index.php3#headers

The way to compile a module on linux 2.4 is:

gcc -O2 -Wall -I/path/to/kernel/include/directory -D__KERNEL__ -DMODULE -c hello.c


Erik

--
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/