LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 09-16-2003, 04:18 AM   #1
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Rep: Reputation: 0
Question building a module


Iam getting an error while linking the following module to my kernel......

//module.c

#define MODULE
#include<linux/module.h>
#include<linux/kernel.h>

int init_module()
{
printk("<1> HEllo my boss\n");
return 0;
}

void cleanup_module()
{

printk("<1> good bye my boss");
}

i can able to compile success fully...

# gcc -c module.c

but when iam trying to insert this module....
# insmod ./module.o

Iam getting this erro..
your kernel is mismatched..
your kernel version is 2.4.0-20.this is compiled for
2.4.0 on linux 9.0...

even i tried on linux 7.0 here also iam getting same error..
your kernel is mismatched..
your kernel version is 2.....this is compiled for
2.4.0 on linux 7.0...


can any one help for this experts..
-------------
mahi
 
Old 09-16-2003, 01:07 PM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
The kernel will not load modules compiled for another kernel version.

I advise you to go to this URL,

Linux Documentation Project - LKM

in the first chapter it explains what needs to be done.


-hope that helps, sorry I couldnt give a longer explaination. I dont have my "linux device drivers" book handy.
 
Old 09-17-2003, 02:55 AM   #3
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thank you mr.jinksys...

for givin this valuable information..
 
Old 09-17-2003, 01:20 PM   #4
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
You are so very welcome.
 
Old 09-18-2003, 09:22 AM   #5
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Can u help me little bit brief...i gothroughed the pdf...but still iam getting the same error...


if it possible can u help me with detail..
 
Old 09-18-2003, 03:45 PM   #6
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Linux Device Drivers, by O' Reilly is now online in full text

http://www.xml.com/ldd/chapter/book/
 
Old 09-18-2003, 03:46 PM   #7
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
can you post how you compile your code? Could you also email your code to jinksys444@charter.net?
 
Old 09-22-2003, 03:39 AM   #8
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Hai...


#define MODULE
#include<linux/module.h>
#include<linux/kernel.h>

int init_module()
{
printk("<1> HEllo my boss\n");
return 0;
}

void cleanup_module()
{

printk("<1> good bye my boss");
}



after finishing this code i come out of the vi editor...and..

i compiled like # gcc -c module.c
#insmod ./module.o
here iam getting the error like ur kernel version mismatched..

rgds,
mahesh
 
Old 09-22-2003, 05:30 AM   #9
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Thanks for posting and emailing your code.

You were compiling your module incorrectly.
Before you can compile your module, you must be
sure that the kernel sources you have installed are
the same version as the running kernel. To remedy this,
you need to do two things.

1) execute this command...

Code:
cp /boot/vmlinuz.version.h /lib/modules/`uname -r`/build/include/linux/version.h
The file /boot/vmlinuz.version.h contains the running kernel's version
information, and will override the kernel source's version macros.

2) you need to compile your modules like this...

Code:
gcc -I/lib/modules/`uname -r`/build/include  -c mymod.c -o mymod
Then, your module should be compiled and ready to be loaded.
Execute
Code:
insmod ./yourmodhere
and your module
should be loaded. On my machine printk's output was printed in my logs and not on the terminal. Depending on your kernel version and your klogd configuration, your results may vary.

Hope I helped.
 
Old 09-22-2003, 09:27 AM   #10
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Mr. jinksys..

I have tried in linux 7.0 my kernel version is 2.2.16-22..here i couldn't find the file like vmlinuz.version.h in /boot directory..


u told about the kernel 2.4....or 2.2...

in my workplace i have the linux 7.0

in my pc i have linux..9.0..

right now iam trying with linux 7.0...

can u help me...

rgds,
mahesh
 
Old 09-22-2003, 10:43 AM   #11
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
You say linux 7 and linux 9, what distro are you talking about?
Redhat, suse, mandrake, etc?
 
Old 09-23-2003, 03:12 AM   #12
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Iam talking about redhat linux 7.0 and redhat Linux 9.0.

i have follwed ur method ..but while copying

cp /boot/vmlinuz.version.h /lib/modules/`uname -r`/build/include/linux/version.h


it is giving error...
that there is no file like vmlinuz.version.h

i tried it in both redhat linux 7.0 and redhat linux 9.0...

i can't able to build the module...

help me on this..
 
Old 09-23-2003, 06:32 AM   #13
manu_s
LQ Newbie
 
Registered: Sep 2003
Posts: 4

Rep: Reputation: 0
hey i am trying to do somethign exactly similar and i am stuck on the same problem...will u plz tell me if u find out how to solve the version problem for hello world program. I am using RH9 2.4.20-8
 
Old 10-03-2003, 01:52 AM   #14
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Hai experts...

Could u help for this problem......

I can't able to build a module ......
 
Old 10-05-2003, 01:06 AM   #15
bmahesh
Member
 
Registered: Sep 2003
Location: Bangalore
Distribution: RedHat , Debian
Posts: 42

Rep: Reputation: 15
module build

Hi,

Pls let me know whether your kernel is compiled with
module version support = yes.
if not do that.

after this compile the module source code with following command

#gcc -D__KERNEL__ -DMODULE -c -I/usr/src/linux-XX/include module.c

where /usr/src/linux-XX will be your source directory path.
and 'module.c' is your source file(module prog. code)

then just folow with 'insmod'

I hope that you will succeed this.
if you have any problem let me know.
Regards
Mahesh
 
  


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
Building an ATI driver module Elomis Linux - Software 2 01-12-2005 02:50 PM
Problems building fglrx module.. synthesiz3d Linux - Newbie 1 12-18-2004 12:30 PM
Building a module within a kernel brianvdc Linux - General 1 12-11-2003 09:13 PM
Building usbvision module in RH 7.3 linuxBill Linux - Software 0 11-03-2003 10:22 AM
Building IDE support as a module johnmcauliffe Linux - General 1 09-03-2003 10:50 AM


All times are GMT -5. The time now is 12:53 AM.

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