* Small problem, Can anybody help me?
@ 2004-05-06 14:01 Srinivas G.
2004-05-06 14:28 ` Erik Mouw
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Srinivas G. @ 2004-05-06 14:01 UTC (permalink / raw)
To: linux-kernel
Hi,
I have written a small hello.c program in the Linux Kernel version
2.4.18-3.
The code is as follows.
-----------------------
define MODULE
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
int Test_init(void)
{
printk("<1> 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'
/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 `}'
The errors came due to a mistake in linux header file. Is it so...
Thanks in advance for any help you can come up with.
Regards,
Srinivas G
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Small problem, Can anybody help me?
2004-05-06 14:01 Small problem, Can anybody help me? Srinivas G.
@ 2004-05-06 14:28 ` Erik Mouw
2004-05-06 17:27 ` David Woodhouse
2004-05-06 14:33 ` Dave Jones
2004-05-06 15:47 ` Richard B. Johnson
2 siblings, 1 reply; 5+ messages in thread
From: Erik Mouw @ 2004-05-06 14:28 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-kernel
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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Small problem, Can anybody help me?
2004-05-06 14:28 ` Erik Mouw
@ 2004-05-06 17:27 ` David Woodhouse
0 siblings, 0 replies; 5+ messages in thread
From: David Woodhouse @ 2004-05-06 17:27 UTC (permalink / raw)
To: Erik Mouw; +Cc: Srinivas G., linux-kernel
On Thu, 2004-05-06 at 16:28 +0200, Erik Mouw wrote:
> 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
That doesn't always work. It gets the CFLAGS wrong. You should always
use
make -C $KERNELDIR SUBDIRS=`pwd` modules
--
dwmw2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Small problem, Can anybody help me?
2004-05-06 14:01 Small problem, Can anybody help me? Srinivas G.
2004-05-06 14:28 ` Erik Mouw
@ 2004-05-06 14:33 ` Dave Jones
2004-05-06 15:47 ` Richard B. Johnson
2 siblings, 0 replies; 5+ messages in thread
From: Dave Jones @ 2004-05-06 14:33 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-kernel
On Thu, May 06, 2004 at 07:31:56PM +0530, Srinivas G. wrote:
> 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'
> /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 `}'
You're trying to include userspace headers into a kernel module.
This won't fly.
> The errors came due to a mistake in linux header file. Is it so...
>
> Thanks in advance for any help you can come up with.
Last week you claimed "Linux has broken spinlocks", this week "broken includes".
I suggest a trip to http://www.kernelnewbies.org/ may be in order
before you tackle anything more complicated than a helloworld module.
Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Small problem, Can anybody help me?
2004-05-06 14:01 Small problem, Can anybody help me? Srinivas G.
2004-05-06 14:28 ` Erik Mouw
2004-05-06 14:33 ` Dave Jones
@ 2004-05-06 15:47 ` Richard B. Johnson
2 siblings, 0 replies; 5+ messages in thread
From: Richard B. Johnson @ 2004-05-06 15:47 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-kernel
On Thu, 6 May 2004, Srinivas G. wrote:
>
> Hi,
>
> I have written a small hello.c program in the Linux Kernel version
> 2.4.18-3.
>
> The code is as follows.
> -----------------------
>
>
> define MODULE
#define __KERNEL__
#include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/init.h>
>
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5557.45 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-05-06 17:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-06 14:01 Small problem, Can anybody help me? Srinivas G.
2004-05-06 14:28 ` Erik Mouw
2004-05-06 17:27 ` David Woodhouse
2004-05-06 14:33 ` Dave Jones
2004-05-06 15:47 ` Richard B. Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox