Fedora Linux Support Community & Resources Center
  #1  
Old 24th February 2007, 12:28 AM
bman Offline
Registered User
 
Join Date: Nov 2006
Location: Ireland
Age: 29
Posts: 92
Problem with kernel source code

Hey,

I'm trying to compile a module for a project at college but when I try to compile this code:

Code:
#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* 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");
}
using this make file:

Code:
TARGET  := hello-1
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

I get the following errors/warnings:

Code:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include   -c -o hello-1.o hello-1.c
hello-1.c:4:55: error: linux/module.h: No such file or directory
hello-1.c:9: warning: no previous prototype for ‘init_module’
hello-1.c: In function ‘init_module’:
hello-1.c:10: warning: implicit declaration of function ‘printk’
hello-1.c: At top level:
hello-1.c:18: warning: no previous prototype for ‘cleanup_module’
hello-1.c: In function ‘cleanup_module’:
hello-1.c:19: error: ‘KERN_ALERT’ undeclared (first use in this function)
hello-1.c:19: error: (Each undeclared identifier is reported only once
hello-1.c:19: error: for each function it appears in.)
hello-1.c:19: error: expected ‘)’ before string constant
make: *** [hello-1.o] Error 1
I followed up the link to /lib/modules/2.6.19-1.2911.fc6/build but it seems to be pointing to /usr/src/kernels/2.6.19-1.2911.fc6-i686/include. Now heres the problem, I don't have a i686 folder here, I have a i586 folder instead. I tried manually inseting the path to the i586 folder instead but I get a load more errors, most of which seem to be division by zero errors. Examples are shown below.

Code:
/usr/src/kernels/2.6.19-1.2911.fc6-i586/include/linux/jiffies.h:33:3: error: #error You lose.
/usr/src/kernels/2.6.19-1.2911.fc6-i586/include/linux/jiffies.h:225:31: error: division by zero in #if
I found the "error You lose." output very useful!

So any ideas on whats wrong here? Should I have the source code for the i686 kernel? Or should the above work okay? If I do need the i686 files then how do I get them?

I hope someone can help me out with this.

Brendan

PS. Sorry about the length of the post.
Reply With Quote
  #2  
Old 24th February 2007, 12:50 AM
brunson Offline
Registered User
 
Join Date: Jun 2005
Location: Westminster, Colorado
Posts: 2,306
You probably don't have the kernel-devel package the corresponds to your kernel build.
Code:
ebrunsonlx(~)$ rpm -q kernel kernel-devel
kernel-2.6.19-1.2911.fc6
kernel-devel-2.6.19-1.2911.fc6
They need to match, as make rule relies on grabbing the version of the running kernel:
Code:
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
If that's not the case, post back and I'll try compiling your little test.
__________________
Registered Linux User #4837
411th in line to get sued by Micro$oft
Quote:
Basically, to learn Unix you learn to understand and apply a small set of key ideas and achieve expertise by expanding both the set of ideas and your ability to apply them - Paul Murphy
Reply With Quote
  #3  
Old 24th February 2007, 12:53 AM
bman Offline
Registered User
 
Join Date: Nov 2006
Location: Ireland
Age: 29
Posts: 92
Thanks for the fast reply. I get:

Code:
[brendanm@localhost ~]$ rpm -q kernel kernel-devel
kernel-2.6.19-1.2895.fc6
kernel-2.6.19-1.2911.fc6
kernel-devel-2.6.19-1.2895.fc6
kernel-devel-2.6.19-1.2911.fc6
Reply With Quote
Reply

Tags
code, kernel, problem, source

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to install the source code of kernel goldenfort Using Fedora 4 21st October 2006 05:46 PM
Where Is Kernel Source Code megadeth Installation, Upgrades and Live Media 4 25th February 2005 09:12 AM
If I get source code of sii6514.o , can solve kernel problem. return Using Fedora 2 30th December 2004 05:08 AM
Source code for kernel-2.6.6-1.427 egurski Installation, Upgrades and Live Media 2 13th June 2004 03:47 AM


Current GMT-time: 20:18 (Wednesday, 26-11-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Mutuali Travel Photos on Instagram - Lufkin Travel Photos on Instagram - Angers Instagram Photos