Re: 'hello world' module

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

 



Hi Ilan,

I don't know about the Oh Really! version, but this one taken from 'Beginning 
Linux Programming' (forward by Alan Cox!) ISBN 1-861002-97-1 worked OK for 
me.

2.4.31, GCC 3.4.4

Build like:

gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c -o 
hello.o

Edit hello.c to suit:



#include <linux/module.h>

#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/kernel.h>

MODULE_AUTHOR ("Nick Warne <[email protected]>");
MODULE_DESCRIPTION ("Hello Kernel! module");
MODULE_LICENSE("GPL");

int init_module(void)
{
        printk(KERN_DEBUG "Hello, kernel!\n");
        return 0;
}

void cleanup_module(void)
{
        printk(KERN_DEBUG "Good-bye, kernel!\n");
}



bash-2.05b# insmod hello.o
bash-2.05b# dmesg | tail -n1
Hello, kernel!

bash-2.05b# lsmod
Module                  Size  Used by    Tainted: P
hello                    320   0  (unused)

bash-2.05b# rmmod hello
bash-2.05b# dmesg | tail -n1
Good-bye, kernel!



Hope that helps.

Nick
-- 
"When you're chewing on life's gristle,
Don't grumble, Give a whistle..."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux