LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 08-12-2008, 12:49 AM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
Unable to compile "hello world" module on openSuse11


Good day,

Same module install/works on FC6 machine.
here are the out puts.

MAke file
Code:
champ@linux-r9za:~/driver> ls
Makefile  hello-1.c

champ@linux-r9za:~/driver> cat Makefile 

bj-m += hello-1.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Hello world module, it complie runs on my FC6 machine.
Code:
champ@linux-r9za:~/driver> 
champ@linux-r9za:~/driver> cat hello-1.c 
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

int init_module(void)
{
	printjkk(KERN_INFO "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_INFO "Goodbye world 1.\n");
}
Build process:
Code:
champ@linux-r9za:~/driver> make
make -C /lib/modules/2.6.25.5-1.1-pae/build M=/home/champ/driver modules
make[1]: Entering directory `/usr/src/linux-2.6.25.5-1.1-obj/i386/pae'
make -C /usr/src/linux-2.6.25.5-1.1 O=/usr/src/linux-2.6.25.5-1.1-obj/i386/pae/. modules
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-2.6.25.5-1.1-obj/i386/pae'
champ@linux-r9za:~/driver> champ@linux-r9za:~/driver> ls
Makefile  Module.symvers  hello-1.c  modules.order
champ@linux-r9za:~/driver>

I think I have every thing installed
Code:
champ@linux-r9za:~/driver> rpm -aq | grep kernel
kernel-pae-2.6.25.5-1.1
linux-kernel-headers-2.6.25-8.1
kernel-source-2.6.25.5-1.1
kernel-syms-2.6.25.5-1.1
champ@linux-r9za:~/driver>

Any Ideas?

Thanks.

Last edited by knockout_artist; 08-12-2008 at 12:53 AM.
 
Old 08-12-2008, 12:57 AM   #2
unikgila
LQ Newbie
 
Registered: Jul 2008
Posts: 27

Rep: Reputation: 15
I used the Redhat, but i used the gcc instead of make. How about change your Makefile with this one:

Makefile
Code:
#Makefile for buidling a module, 08/06/2008
CC=gcc

MODCFLAGS := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include

all:    hello-1.o hello-3.o hello-4.o hello-5.o



hello-1.o:      hello-1.c
                $(CC) $(MODCFLAGS) -c hello-1.c

hello-3.o:      hello-3.c
                $(CC) $(MODCFLAGS) -c hello-3.c


hello-4.o:      hello-4.c
                $(CC) $(MODCFLAGS) -c hello-4.c


hello-5.o:      hello-5.c
                $(CC) $(MODCFLAGS) -c hello-5.c

clean:
                rm -f hello-1.o hello-3.o hello-4.o hello-5.o
 
Old 08-12-2008, 01:03 AM   #3
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
Thanks.

I tried your make file that what I got

Code:
champ@linux-r9za:~/driver> make
Makefile:11: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.
 
Old 08-12-2008, 01:11 AM   #4
unikgila
LQ Newbie
 
Registered: Jul 2008
Posts: 27

Rep: Reputation: 15
Yes using tab instead of spaces
 
Old 08-12-2008, 01:13 AM   #5
unikgila
LQ Newbie
 
Registered: Jul 2008
Posts: 27

Rep: Reputation: 15
Yes using tab instead of spaces
 
Old 08-12-2008, 01:57 AM   #6
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
I used command from your makefile thats what I got now


Code:
champ@linux-r9za:~/driver> gcc -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include -c hello-1.c 
hello-1.c:1:54: error: linux/module.h: No such file or directory
hello-1.c: In function 'init_module':
hello-1.c:6: warning: implicit declaration of function 'printk'
hello-1.c:6: error: 'KERN_INFO' undeclared (first use in this function)
hello-1.c:6: error: (Each undeclared identifier is reported only once
hello-1.c:6: error: for each function it appears in.)
hello-1.c:6: error: expected ')' before string constant
hello-1.c: At top level:
hello-1.c:14: error: expected identifier or '(' before '{' token
champ@linux-r9za:~/driver>
 
Old 08-12-2008, 04:58 AM   #7
unikgila
LQ Newbie
 
Registered: Jul 2008
Posts: 27

Rep: Reputation: 15
Ehm, i don't know why you don't have module.h. Have you look in linux directory? just using ls command:

ls /usr/include/linux/module.h

if no try to locate where is module.h, or may be you also can try find in the kernel source
ls /usr/src/linux(your version)/include/linux/module.h

if you find it here, i think you have to modify your Makefile using above path.
 
  


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
Trying to Compile "hello world" Kernel Module (please help!) antdengineer Programming 9 12-04-2010 04:07 AM
noob having problems to compile first Qt "hello world" application joakim12 Programming 4 06-03-2010 08:39 AM
ocfs2 Unable to load module "configfs" pjohnson Linux - Newbie 1 06-19-2008 04:37 PM
Install ati-drivers fails with "Failed to compile kernel module" erpe Debian 2 06-13-2006 05:09 AM
"unable to find the dependent module" reji vl Linux - Software 0 01-22-2004 07:55 AM


All times are GMT -5. The time now is 09:54 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration