LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Problem of Linux kernel version mismatch while running the compile program (https://www.linuxquestions.org/questions/linux-kernel-70/problem-of-linux-kernel-version-mismatch-while-running-the-compile-program-500012/)

Nishant Desai 11-09-2006 05:35 AM

Problem of Linux kernel version mismatch while running the compile program
 
Dear All,

I want to run this program (simple program related to device driver):

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

int init_module (void) /* Loads a module in the kernel */
{
printk("Hello kernel n");
return 0;
}

void cleanup_module(void) /* Removes module from kernel */
{
printk("GoodBye Kerneln");
}

Compiling the module

# gcc -c hello.c
# insmod hello.o

The output is

Hello kernel

The procedure is going right upto compiling the program, but when i am trying to run "insmod hello.o", it give me an error as:

hello.o: kernel-module version mismatch
hello.o was compiled for kernel version 2.4.20
while this kernel is version 2.4.20-8.

It mean the gcc i am using for compile the program is different from the current kernel version, but to change the gcc to the current kernel where should i look in the Linux? what could be the method to get to the right gcc of the current kernel version?\

Thanks,
Nishant Desai

Mara 11-09-2006 04:12 PM

It's not about gcc, it's about the kernel headers you use to complile your module. Running kernel is 2.4.20-8, but headers say 2.4.20. I guess you have downloaded and installed 2.4.20 vanilla sources while you're running kernel from your distribution. You have two options:
1. install kernel sources from your distribution (version 2.4.20-8 to match the running kernel)
2. compile kernel using the sources you have, then switch to it

Nishant Desai 11-09-2006 11:58 PM

Quote:

Originally Posted by Mara
It's not about gcc, it's about the kernel headers you use to complile your module. Running kernel is 2.4.20-8, but headers say 2.4.20. I guess you have downloaded and installed 2.4.20 vanilla sources while you're running kernel from your distribution. You have two options:
1. install kernel sources from your distribution (version 2.4.20-8 to match the running kernel)
2. compile kernel using the sources you have, then switch to it

Dear Mara,

I could not get you exactly about this reply, pls explain me "It's not about gcc, it's about the kernel headers you use to complile your module. Running kernel is 2.4.20-8, but headers say 2.4.20.", what is that? does it mean that even with my same kernel, i can run this program or i have to switch to the kernel 2.4.20? what is the difference in the running kernel and the headers, which i am calling?

I simply have install the RH9, as i am newbie and i also found the same question as i have in this forum for the same distro(RH 9), so i think this is the basic problem of RH 9...! bus i am in doubt that is it possible that this kind of distributors can do this kind of mistake?

By this statements :

two options:
1. install kernel sources from your distribution (version 2.4.20-8 to match the running kernel) - what should i do? shold i switch to kernel 2.4.20?

2. compile kernel using the sources you have, then switch to it - From which sources i should compile and where to switch?

Pls... explain me...

Thanks,
Nishant

Mara 11-10-2006 03:37 PM

Quote:

Originally Posted by Nishant Desai
Dear Mara,

I could not get you exactly about this reply, pls explain me "It's not about gcc, it's about the kernel headers you use to complile your module. Running kernel is 2.4.20-8, but headers say 2.4.20.", what is that? does it mean that even with my same kernel, i can run this program or i have to switch to the kernel 2.4.20? what is the difference in the running kernel and the headers, which i am calling?

Driver (that's what you're writing) is not a normal program. It's a part of your kernel. That's why it must meet a number of requirements which do not exist for normal programs.

The version must match. It's important to see when you can change it, however. When you look into the kernel sources, you can see it in Makefile in the main kernel dir (VERSION=, PATCHLEVEL=, SUBLEVEL= and EXTRAVERSION=). Extraversion can also be changed when configuring your kernel. Extraversion is basically that "-8" you have. I'll come back to that later.

Quote:

I simply have install the RH9, as i am newbie and i also found the same question as i have in this forum for the same distro(RH 9), so i think this is the basic problem of RH 9...! bus i am in doubt that is it possible that this kind of distributors can do this kind of mistake?
So you have kernel installed directly from your distribution? It's important, because distribution vendors patch their kernels quite heavily, what means that 2.4.20 (which usually is then given name 2.4.20-something) shipped with the distro is not the same as 2.4.20 downloaded from kernel.org.

Quote:

By this statements :

two options:
1. install kernel sources from your distribution (version 2.4.20-8 to match the running kernel) - what should i do? shold i switch to kernel 2.4.20?
You do have version 2.4.20, but patched by RedHat. It means that, if you have the kernel from RH installed, it should be enough to change to EXTRAVERSION to 8 and you have quite a good changes it will work with just that.

Quote:

2. compile kernel using the sources you have, then switch to it - From which sources i should compile and where to switch?
That's the solution if you don't have RH kernel installed and you have downloaded kernel from kernel.org. Then you need to run the same kernel you write your module for. It means you need to compile the whole kernel (from the dowloaded sources), then add new kernel to grub/lilo and choose that new one at reboot (and work with your module with that version).

It seems you have RH kernel, so this option is not the easiest way to go in this case.

Nishant Desai 11-28-2006 05:54 AM

Quote:

Originally Posted by Mara
Driver (that's what you're writing) is not a normal program. It's a part of your kernel. That's why it must meet a number of requirements which do not exist for normal programs.

The version must match. It's important to see when you can change it, however. When you look into the kernel sources, you can see it in Makefile in the main kernel dir (VERSION=, PATCHLEVEL=, SUBLEVEL= and EXTRAVERSION=). Extraversion can also be changed when configuring your kernel. Extraversion is basically that "-8" you have. I'll come back to that later.


So you have kernel installed directly from your distribution? It's important, because distribution vendors patch their kernels quite heavily, what means that 2.4.20 (which usually is then given name 2.4.20-something) shipped with the distro is not the same as 2.4.20 downloaded from kernel.org.


You do have version 2.4.20, but patched by RedHat. It means that, if you have the kernel from RH installed, it should be enough to change to EXTRAVERSION to 8 and you have quite a good changes it will work with just that.


That's the solution if you don't have RH kernel installed and you have downloaded kernel from kernel.org. Then you need to run the same kernel you write your module for. It means you need to compile the whole kernel (from the dowloaded sources), then add new kernel to grub/lilo and choose that new one at reboot (and work with your module with that version).

It seems you have RH kernel, so this option is not the easiest way to go in this case.

Dear Mara,

Let me come back to this point again, now i have install the kernel 2.6.18-3y and there are two kernels inside my desktop, i can run either of them at the boot up selection, but the surprising thing is after upgrading it to 2.6.18, it is still compiling the program for the 2.4.20 kernel.

So my question, what should i do to upgrade my gcc while i upgrade my kernel, is it necessary toupgrade my kernel?

How i will come to know that which gcc is compatible for my kernel, because the kernel is downloaded from kernel.org, and there is nothing specified with the kernel. Pls help me.

Thanks,
Nishant

Mara 11-28-2006 02:24 PM

gcc ic compatibile with both kernels, but it may be searching for headers in wrong places. Do you have /usr/src/linux? It probably points to the old kernel. You can switch the symlink (it's probably just a symlink) or write your makefiles in such a way that the new kernel dierectory will be first on the list (or add an option to specify the kernel header dir).

Nishant Desai 11-28-2006 11:35 PM

Quote:

Originally Posted by Mara
gcc ic compatibile with both kernels, but it may be searching for headers in wrong places. Do you have /usr/src/linux? It probably points to the old kernel. You can switch the symlink (it's probably just a symlink) or write your makefiles in such a way that the new kernel dierectory will be first on the list (or add an option to specify the kernel header dir).

Dear Mara,

Does it mean that when I am calling my headers as <linux/module.h>, then it is calling from the symlink?

But suppose there is no symlink of the name linux, then still my program is running, then what could be the problem?

Another thing my current symlink points to the same version which is running, but still it is giving me an error.

Thanks,
Nishant

Mara 12-01-2006 03:04 PM

It depends on the distro. There may be a symlink but also the initial version (headers from default kernel) may be copied.
Please check what does the version you're currently running have in Makefile (especially SUBVERSION=).

thangam 03-12-2007 08:22 AM

Hi Nishant,

Me aslo has the same problem ...i am wondering by seeing this..this..some one know about this ..plz give us a good solution ASAP.

i think this is checking the version match with version header file.that is mismatch between the make file version Vs version.h file.kindly ckeck & give as solutiion..

Thankx
Arun


All times are GMT -5. The time now is 08:49 AM.