2005-05-07 13:19:48

by li nux

[permalink] [raw]
Subject: compiling "hello world" kernel module on 2.6 kernel

I have written a minimal hello world kernel module.
(see the Makefile and hello.c below)
But I am not able to build it using the kernel build
system.Any idea why this is happening.

I referred "Chapter 2: Building and Running Modules"
of
http://www.oreilly.com/catalog/linuxdrive3/book/index.csp

I am using SLES9
My kernel sources are at /local/usr/linux-2.6.5-7.162
This is the kernel i am running.

On doing a make it gives me following output, but does
not build hello.o
----------------------------------------------
$ make
make -C /lib/modules/2.6.5-7.162-bigsmp/build
M=/local/usr/linux-2.6.5-7.162 modules
make[1]: Entering directory
`/local/usr/linux-2.6.5-7.162'
Building modules, stage 2.
MODPOST
make[1]: Leaving directory
`/local/usr/linux-2.6.5-7.162'
--------------------------------------------------
This is my Makefile:

# If KERNELRELEASE is defined, we've been invoked from
# the kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o

# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
---------------------------------------------------
hello.c

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/vermagic.h>

static int __init hello_init (void)
{
printk("module hello loading");
return 0;
}

static void __exit hello_exit (void)
{
printk("module hello exiting");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE ("GPL");
--------------------------------------------------



Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html


2005-05-07 14:05:49

by Espen Fjellvær Olsen

[permalink] [raw]
Subject: Re: compiling "hello world" kernel module on 2.6 kernel

On 5/7/05, li nux <[email protected]> wrote:
>
> default:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

Try changing this to:
" $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules"


--
Mvh / Best regards
Espen Fjellv?r Olsen
[email protected]
Norway

2005-05-07 14:20:34

by li nux

[permalink] [raw]
Subject: Re: compiling "hello world" kernel module on 2.6 kernel

Thanks Espen, but it didnt worked.
Please tell me where i am wrong:
hello.c is at /local/usr/linux-2.6.5-7.162
i did a cd to /local/usr/linux-2.6.5-7.162
created makefile called Makefile.1 as u suggested.
and did a make -f Makefile.1

--- Espen Fjellv?r Olsen <[email protected]> wrote:
> On 5/7/05, li nux <[email protected]> wrote:
> >
> > default:
> > $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
>
> Try changing this to:
> " $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules"
>
>
> --
> Mvh / Best regards
> Espen Fjellv?r Olsen
> [email protected]
> Norway
> -
> 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/
>



Discover Yahoo!
Find restaurants, movies, travel and more fun for the weekend. Check it out!
http://discover.yahoo.com/weekend.html

2005-05-08 18:32:02

by Sam Ravnborg

[permalink] [raw]
Subject: Re: compiling "hello world" kernel module on 2.6 kernel

On Sat, May 07, 2005 at 07:20:26AM -0700, li nux wrote:
> Thanks Espen, but it didnt worked.
> Please tell me where i am wrong:
> hello.c is at /local/usr/linux-2.6.5-7.162
> i did a cd to /local/usr/linux-2.6.5-7.162
> created makefile called Makefile.1 as u suggested.
> and did a make -f Makefile.1

Wrong.
Put hello.c somewhere in you home directory.
The Makefile shall be placed in same directory.

Restore any files you have overwritten in the kernel dir (like the
Makefile)
Then it will work out.

If not post full details including the output of the make command with
V=1 included: $(MAKE) -C $(KERNELDIR) V=1 M=$(PWD)

Sam