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.
I am working my way through the book Linux Device Drivers, 2nd Ed, and came upon a problem with the first example program, a simple module that prints "Hello World!" from the console. G++ doesn't recognize the header I used, as I believe it isn't in the search path. The header in question is linux/module.h. I need a way to see the header search path for g++, and a quick browse through info g++ didn't seem to help much. Does anyone know how to view and edit the search path for G++? Thanks in advance.
Okay. I made it into a .c file and compiled it with gcc as described in the book. Now, I get a new error. Here is how it went.
gcc -c hellomodule.c
insmod ./hellomodule.o
kernel-module version mismatch
./hellomodule.o was compiled for kernel version 2.4.20
while this kernel is bersion 2.4.20-6.
I compiled this on my own machine, so what is going on?
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.