ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am just beginning kernel programming.When I compile a hello Work module and ins-mod it ,I got this message :
hello was compiled for kernel version 2.4.20 while this kernel is version 2.4.20-8
Should I update my kernel ?
Hypothetical situation. Let's say you're in school, studying kernel programming. You have 2.4.20 at home, 2.4.20-8 at school. You have two options: update your kernel at home,so that you're working with the same kernel at both locations. Or, make two copies of the file you want to compile. Compile one at home; the other at school.
Kernel modules are not portable. They look for the specific kernel they were compiled on. Ok, not the specific kernel persay, but a kernel that reports the exact same server string. The best thing to do is like bigrig said, always build the module against the kernel you intend to use it with. Transfer source code, not binaries.
Add the following to your gcc command line. It appears to fix the error for me. There will still be a warning about there being no license and therefore it might taint the kernel, but the kernel version problem seems to go away.
(You might need to put some version information after linux in the path. Search your filesystem to see what the correct path would be.)
-isystem /usr/src/linux/include
This is the command line that worked for me in the hello world module from "Linux Device Drivers" 2nd Edition. ( I defined __KERNEL__ and MODULE in the code.)
gcc -c -isystem /usr/src/linux/include hello.c
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.