Compile a kernel module
I'm having problems to compile a simple Hello World module. I'm using the kernel 2.6 with a SUSE 10.0 distribution and gcc 4.0.2.
The problem is that the Makefile doesn't compile the module, it doesnt create .o or .ko objects. Can anyone help? *** Here is the code: #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello World\n"); return 0; } static void hello_cleanup(void) { printk(KERN_ALERT "Bye!\n"); } module_init(hello_init); module_exit(hello_cleanup); *** The Makefile: obj-m := hello.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules *** The Output: unit1:/home/rui/module # make make -C /lib/modules/2.6.13-15-smp/build SUBDIRS=/home/rui/module modules make[1]: Entering directory `/usr/src/linux-2.6.13-15-obj/i386/smp' make -C ../../../linux-2.6.13-15 O=../linux-2.6.13-15-obj/i386/smp modules Building modules, stage 2. MODPOST make[1]: Leaving directory `/usr/src/linux-2.6.13-15-obj/i386/smp' |
You need a tab character before $(MAKE) in the default rule. Not spaces... a tab.
|
Actually there is a TAB before $(MAKE) in my Makefile. Without the tab the message is diferent. It says that there is nothing to be done for default.
The question continues... |
Sorry, looks like no whitespace at all in the original post.
I have to rebuild a kernel network module with each new Fedora kernel release if I want IPv6 to work. Here's how I do it. Maybe it'll help... Code:
[root@osprey net]# pwd |
That's exactly what I wanted. But didn't get it...
I'm wondering about the file vermagic.o. That file should be in /init and doesn't appear in my directory. I read that all the modules must pass through a linking step with this file. Does it appear for you? Do you know how can I create it? Maybe I forgot something in the kernel's configuration. |
I have no vermagic.o anywhere on my system.
I did notice one difference between your Makefile and mine; you have "SUBDIRS=" where I have "M=". I don't really know if it's important or not. |
All times are GMT -5. The time now is 04:35 PM. |