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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-20-2003, 07:20 PM
|
#1
|
LQ Newbie
Registered: Oct 2003
Location: Bangalore, India
Distribution: Redhat Linux 9.0
Posts: 2
Rep:
|
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.
|
|
|
10-21-2003, 07:38 AM
|
#2
|
Member
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246
Rep:
|
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.
|
|
|
10-21-2003, 08:28 AM
|
#3
|
LQ Newbie
Registered: Oct 2003
Location: Bangalore, India
Distribution: Redhat Linux 9.0
Posts: 2
Original Poster
Rep:
|
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.
|
|
|
10-22-2003, 07:30 AM
|
#4
|
Member
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246
Rep:
|
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.
|
|
|
10-23-2003, 04:18 PM
|
#5
|
Member
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 01:23 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|