Re: Help!! How to write an easy module on SuSE 8.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed 18 June 2003 23:03, Juan Torres wrote:
> Hello:
>
> I have been trying to write the easiest module "Hello World" on SuSE 8.0
> (2.4.18-4GB kernel version), but I can't.
>
> If I use the next code for my hello.c file:
>
> #define MODULE
> #include <linux/module.h>
> #include <linux/kernel.h>
>
> int init_module(void)
> {
>     printk("Hello world\n");
>     return 0;
> }
>
> void cleanup_module(void)
> {
>     printk("Bye world\n");
> }
>
>
> When I use the command insmod hello.c, it appears an error saying that
> it is compiled for the 2.4.17 kernel version, and I am using the
> 2.4.18-4GB version.


> I have tried it with this other code:
>
> #include <linux/init.h>
> #include <linux/module.h>
> #include <linux/kernel.h>
>
> static int hello_init(void)
> {
>     printk("Hello world\n");
>     return 0;
> }
>
> static void hello_exit(void)
> {
>     printk("Bye world\n");
> }
>
> module_init(hello_init);
> module_exit(hello_exit);
> MODULE_LICENSE("GPL");
>
> In this case I got an error saying that it can't identify the kernel
> version
>
> To compile the hello.c file I'm using the next command: gcc -c hello.c
> (I don't know if could be here the problem, of course, I'm a kernel
> newbie)
>
> Thank you very much...

both source codes are correct, (the later is better, it avoid stressing warning messages when insmoding) but they aren't compiled correctly.

you need to compile hello.c with:
gcc -D__KERNEL__ -DMODULE -c -I/usr/src/linux-`uname -r`/include hello.c

now you can load safely your kernel module as follow:
insmod hello.o




Daniele.


PGP PKEY      http://pgp.mit.edu:11371/pks/lookup?search=belch76@libero.it&op=index
ICQ#               104896040  
Netphone/Fax  178.605.7063
Homepage       http://web.tiscali.it/bellucda




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux