LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2006, 04:05 PM   #1
Ralc
LQ Newbie
 
Registered: Mar 2006
Location: Brazil
Posts: 4

Rep: Reputation: 0
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'
 
Old 03-10-2006, 10:39 PM   #2
jcliburn
Member
 
Registered: Dec 2003
Location: Mississippi, USA
Distribution: Fedora
Posts: 435

Rep: Reputation: 33
You need a tab character before $(MAKE) in the default rule. Not spaces... a tab.
 
Old 03-11-2006, 08:35 AM   #3
Ralc
LQ Newbie
 
Registered: Mar 2006
Location: Brazil
Posts: 4

Original Poster
Rep: Reputation: 0
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...
 
Old 03-11-2006, 09:06 AM   #4
jcliburn
Member
 
Registered: Dec 2003
Location: Mississippi, USA
Distribution: Fedora
Posts: 435

Rep: Reputation: 33
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
/usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15/drivers/net
[root@osprey net]# ls -l via-velocity*
-rw-r--r--  2 root root 88117 Mar  2 18:28 via-velocity.c
-rw-r--r--  2 root root 50028 Jan  2 21:21 via-velocity.h
[root@osprey net]# cat Makefile
obj-m := via-velocity.o

KDIR  := /lib/modules/$(shell uname -r)/build
PWD   := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) M=$(PWD) modules

[root@osprey net]# make
make -C /lib/modules/2.6.15-1.1833_FC4/build M=/usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15/drivers/net modules
make[1]: Entering directory `/usr/src/kernels/2.6.15-1.1833_FC4-x86_64'
  CC [M]  /usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15/drivers/net/via-velocity.o
  Building modules, stage 2.
  MODPOST
  CC      /usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15/drivers/net/via-velocity.mod.o
  LD [M]  /usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15/drivers/net/via-velocity.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.15-1.1833_FC4-x86_64'
[root@osprey net]# ls -l via-velocity*
-rw-r--r--  2 root root  88117 Mar  2 18:28 via-velocity.c
-rw-r--r--  2 root root  50028 Jan  2 21:21 via-velocity.h
-rw-r--r--  1 root root 426144 Mar 11 07:58 via-velocity.ko
-rw-r--r--  1 root root   2957 Mar 11 07:58 via-velocity.mod.c
-rw-r--r--  1 root root  44960 Mar 11 07:58 via-velocity.mod.o
-rw-r--r--  1 root root 382592 Mar 11 07:58 via-velocity.o
[root@osprey net]#
 
Old 03-11-2006, 09:43 AM   #5
Ralc
LQ Newbie
 
Registered: Mar 2006
Location: Brazil
Posts: 4

Original Poster
Rep: Reputation: 0
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.

Last edited by Ralc; 03-11-2006 at 09:45 AM.
 
Old 03-11-2006, 09:51 AM   #6
jcliburn
Member
 
Registered: Dec 2003
Location: Mississippi, USA
Distribution: Fedora
Posts: 435

Rep: Reputation: 33
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't compile kernel with agpgart as module rabalder321 Linux - Newbie 2 12-23-2005 10:22 PM
Compile in kernel or module? maginotjr Slackware 4 06-30-2005 12:54 PM
can't Compile a module under Kernel 2.4.20-8 srsairam Linux - Software 3 11-09-2004 01:45 AM
can i compile just one kernel module whithout recompiling the whole kernel? edman007 Linux - Software 3 02-17-2004 04:05 PM
compile individual kernel module snape Linux - Software 1 06-27-2001 11:25 AM


All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration