|

楼主 |
发表于 2004-2-18 21:28:45
|
显示全部楼层
/************** hello.c ****************/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
int init_module(void)
{
printk("<1>Hello,world\n");
return 0;
}
void cleanup_module(void)
{
printk("<2>Goodbye\n");
}
/**************** makefile ***************/
DFLAGS = -D__KERNEL__ -DMODULE
CFLAGS = -O2 -g -Wall -Wstrict-prototypes -pipe -I/usr/src/linux-2.4/include
hello.o:hello.c
gcc -c hello.c $(DFLAGS) $(CFLAGS) -o hello.o
clean:
rm -f *.o
/**************** 编译时 ****************/
[root@zooka temp]# make
gcc -c hello1.c -D__KERNEL__ -DMODULE -O2 -g -Wall -Wstrict-prototypes -pipe -I/usr/src/linux-2.4/include -o hello.o
hello1.c: In function `init_module':
hello1.c:20: warning: implicit declaration of function `printk'
/************* 加载模块 **************/
[root@zooka temp]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings |
|