LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2003, 07:20 PM   #1
pritesh
LQ Newbie
 
Registered: Oct 2003
Location: Bangalore, India
Distribution: Redhat Linux 9.0
Posts: 2

Rep: Reputation: 0
Getting Incompatibility Errors While Compiling Kernel Module.


Hi,

I am trying to learn Kernel Module Programming by referring

"The Linux Kernel Module Programming Guide" written by
Peter Jay Salzman and Ori Pomerantz downloaded from tldp.org

After some minor changes, the code gets compiled correctly, when I issue gcc -c firstmod.c.
I also see the oject file created named firstmod.o.

Problem is, whenever I try to insert the module by typing

insmod ./firstmod.o

I get an error stating that the module was not inserted because of some kernel compatibility issue.

I apologize for not providing the exact error message, but this is the gist of it.

Here is the 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");
}


I am using Redhat 9.0

Please help me.


Regards,

Pritesh

Last edited by pritesh; 10-20-2003 at 07:21 PM.
 
Old 10-21-2003, 07:38 AM   #2
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
Does it say that the module will taint the kernel, if so add a line MODULE_LICENSE("GPL");.

It is also possible that you have a kernel with versioning support compiled in. This appends a string to the end of each function name you register formed by encoding the parameters, return type, etc. This allows a module compiled for an older kernel to be loaded provided the functions used haven't changed their interface. To support versioning you have to #include <linux/modversions.h> (you may have to do something else too, I can't remember at the moment).

P.S. The KERN_ALERT should come outside the quotation marks.

Last edited by nhs; 10-21-2003 at 07:39 AM.
 
Old 10-21-2003, 08:28 AM   #3
pritesh
LQ Newbie
 
Registered: Oct 2003
Location: Bangalore, India
Distribution: Redhat Linux 9.0
Posts: 2

Original Poster
Rep: Reputation: 0
Hi NHS,

Thank you for the reply.

However, if KERN_ALERT is put outside the quote, I get errors stating that it does not recongnize KERN_ALERT, that its an undeclared variable.
Regards,
Pritesh

Last edited by pritesh; 10-21-2003 at 08:33 AM.
 
Old 10-22-2003, 07:30 AM   #4
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
I think you #include <linux/printk.h> to get KERN_ALERT.You could also try #include <linux/error.h>. If both fail then look in /usr/src/linux/include/linux/*.h for a likely looking file.

I think the commands

cd /usr/src/linux/include
for file in *.h; do grep '#define KERN_ALERT' $file >/dev/null 2>&1 && echo $file;done

should output each file which defines KERN_ALERT.
 
Old 10-23-2003, 04:18 PM   #5
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
Back on a linux box, I've looked at some of my code and realised that your code was missing the lines
#define __KERNEL__
#define MODULE
before any of the #include lines. The __KERNEL__ symbol enables a lot of code that isn't used by user-space code but is by kernel code (eg. KERN_ALERT) and MODULE just includes the module specific code. This should sort your problem.
 
  


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
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 05:03 AM
Major compilation errors in emacs while compiling c code dualcyclone Linux - Software 0 03-26-2004 01:31 PM
G++ - why am i getting errors compiling this simple code leroy27336 Programming 4 11-18-2003 08:32 PM
small errors in kernel code (2.4.22) Robert0380 Linux - General 2 10-06-2003 09:15 AM
code errors FuLL-On-Newbie Linux - General 5 04-11-2003 07:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:23 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
Open Source Consulting | Domain Registration