LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 11-09-2006, 06:35 AM   #1
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Rep: Reputation: 15
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
 
Old 11-09-2006, 05:12 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
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
 
Old 11-10-2006, 12:58 AM   #3
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Original Poster
Rep: Reputation: 15
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
 
Old 11-10-2006, 04:37 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
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.

Last edited by Mara; 11-10-2006 at 04:42 PM.
 
Old 11-28-2006, 06:54 AM   #5
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Original Poster
Rep: Reputation: 15
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
 
Old 11-28-2006, 03:24 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
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).
 
Old 11-29-2006, 12:35 AM   #7
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Original Poster
Rep: Reputation: 15
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
 
Old 12-01-2006, 04:04 PM   #8
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
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=).
 
Old 03-12-2007, 09:22 AM   #9
thangam
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Rep: Reputation: 0
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
 
  


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
help, gcc version and kernel version mismatch akanitkar Linux - Newbie 1 05-06-2006 08:02 AM
Kernel version Source Version mismatch after recompile chuckleberry Linux - Software 1 06-20-2005 07:37 PM
How To Solve The Kernel Module Version Mismatch Problem ? linu_soft Programming 2 07-21-2004 05:47 AM
Linux kernel version mismatch claudiu_t Linux - Software 3 10-12-2003 07:25 AM
kernel version mismatch jimo Linux - Software 3 10-29-2001 02:58 PM


All times are GMT -5. The time now is 10:11 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration