[vikky@server v3tv]$ cat hello.c /* Kernel Programming */ #define MODULE #define LINUX #define __KERNEL__ #include /* Needed by all modules */ #include /* Needed for KERN_ALERT */ int init_module(void) { printk("<1>Hello world 1.\n"); // A non 0 return means init_module failed; module can't be loaded. return 0; } void cleanup_module(void) { printk(KERN_ALERT "Goodbye world 1.\n"); } MODULE_LICENSE("GPL"); [vikky@server v3tv]$ cat tmp.mak TARGET := hello WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes INCLUDE := -isystem /lib/modules/`uname -r`/build/include CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} CC := gcc ${TARGET}.o: ${TARGET}.c .PHONY: clean clean: rm -rf ${TARGET}.o [vikky@server v3tv]$ make -f tmp.mak gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include -c -o hello.o hello.c hello.c:2:1: warning: "MODULE" redefined :1:1: warning: this is the location of the previous definition hello.c:4:1: warning: "__KERNEL__" redefined :1:1: warning: this is the location of the previous definition In file included from /lib/modules/2.6.21.5/build/include/linux/prefetch.h:14, from /lib/modules/2.6.21.5/build/include/linux/list.h:8, from /lib/modules/2.6.21.5/build/include/linux/module.h:10, from hello.c:6: /lib/modules/2.6.21.5/build/include/asm/processor.h:77: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function) /lib/modules/2.6.21.5/build/include/asm/processor.h:77: error: requested alignment is not a constant /lib/modules/2.6.21.5/build/include/asm/processor.h:233: error: requested alignment is not a constant In file included from /lib/modules/2.6.21.5/build/include/linux/kobject.h:25, from /lib/modules/2.6.21.5/build/include/linux/module.h:17, from hello.c:6: /lib/modules/2.6.21.5/build/include/linux/rwsem.h:24:65: error: asm/rwsem.h: No such file or directory In file included from /lib/modules/2.6.21.5/build/include/linux/module.h:17, from hello.c:6: /lib/modules/2.6.21.5/build/include/linux/kobject.h:178: error: field ‘rwsem’ has incomplete type In file included from /lib/modules/2.6.21.5/build/include/linux/memory_hotplug.h:7, from /lib/modules/2.6.21.5/build/include/linux/mmzone.h:463, from /lib/modules/2.6.21.5/build/include/linux/gfp.h:4, from /lib/modules/2.6.21.5/build/include/linux/slab.h:14, from /lib/modules/2.6.21.5/build/include/linux/percpu.h:5, from /lib/modules/2.6.21.5/build/include/asm/local.h:4, from /lib/modules/2.6.21.5/build/include/linux/module.h:19, from hello.c:6: /lib/modules/2.6.21.5/build/include/linux/notifier.h:62: error: field ‘rwsem’ has incomplete type make: *** [hello.o] Error 1 [vikky@server v3tv]$