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 |
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 |
Quote:
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 |
Quote:
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:
Quote:
Quote:
It seems you have RH kernel, so this option is not the easiest way to go in this case. |
Quote:
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 |
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).
|
Quote:
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 |
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=). |
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. |