LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   building a module (https://www.linuxquestions.org/questions/programming-9/building-a-module-93307/)

pessanimahi 09-16-2003 03:18 AM

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

jinksys 09-16-2003 12:07 PM

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.

pessanimahi 09-17-2003 01:55 AM

Thank you mr.jinksys...

for givin this valuable information..

jinksys 09-17-2003 12:20 PM

You are so very welcome.

pessanimahi 09-18-2003 08:22 AM

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..

jinksys 09-18-2003 02:45 PM

Linux Device Drivers, by O' Reilly is now online in full text

http://www.xml.com/ldd/chapter/book/

jinksys 09-18-2003 02:46 PM

can you post how you compile your code? Could you also email your code to jinksys444@charter.net?

pessanimahi 09-22-2003 02:39 AM

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

jinksys 09-22-2003 04:30 AM

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.

pessanimahi 09-22-2003 08:27 AM

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

jinksys 09-22-2003 09:43 AM

You say linux 7 and linux 9, what distro are you talking about?
Redhat, suse, mandrake, etc?

pessanimahi 09-23-2003 02:12 AM

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..

manu_s 09-23-2003 05:32 AM

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

pessanimahi 10-03-2003 12:52 AM

Hai experts...

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

I can't able to build a module ......

bmahesh 10-05-2003 12:06 AM

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


All times are GMT -5. The time now is 09:28 AM.