Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compiling a very simple module

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
I'm writing a kernel module, but am having a little compiling problem. Under Slackware 8 kernel version 2.4.18 this code works:

#define MODULE

#ifndef __KERNEL__
#define __KERNEL__
#endif

#include <linux/module.h>
#include <linux/init.h>

int start(void);
void end(void);

int start(void)
{
printk(&quot;<1>Hey!\n&quot;);
return 0;
}

void end(void)
{
printk(&quot;<1>Bye!\n&quot;);
}

module_init(start);
module_exit(end);

Compile: gcc -c file.c

- Execution -
% insmod ./file.o
Hey!
% rmmod file
Bye!
%

Now that exact code doesn't work under Red Hat 7.3 kernel version 2.4.18-3. I get this error message:

% insmod file.o
file.o: kernel-module version mismatch
file.o was compiled for kernel version 2.4.9-9
while this kernel is version 2.4.18-3.
%


Any thoughts? Thanks.

-bitwise
 
I'm guessing you used the include files from one kernel but you are running a different one. It doesnät automatically use the include files corresponding to the kenrel that is currently running when you compile.

Try to specify that you want to use the include files for kernel 2.4.18-3, not 2.4.9-9 (and make sure that you have the include files for 2.4.18-3 =).
 
Linux has implemented a versioning mechanism and you have just tripped it. If you copy all your source code into the 2.4.18-3 tree from the 2.4.9-9 tree and recompile Ur module,your ismod will run just fine.

cheers
amit
crazy_indian@lycos.com

to bug is human to debug devine
 
Thanks a lot guys. I'm starting to figure out the reason this isn't working. It IS a result of not including the right files for the kernel...some kind of versioning mechanism that both of you had mentioned. Under Slackware 8.0 running kernel 2.4.18 the /usr/include/linux directory is actually a symlink to /usr/src/linux/include/linux/, which would be the headers for the currently running kernel. Red Hat and Debian for some reason don't use symlinks on the /usr/include/linux or the /usr/include/asm directories. They just copy over the files (usually a subset of what is actually in the directories in the kernel source tree). Regardless, this means that you might not be linking the right headers for the currently running kernel. So, under Red Hat I just made the /usr/include/linux directory a symlink to /usr/src/linux/include/linux/ and it worked...sort of. Now I get this error:

&quot;Warning: loading file.o will taint the kernel: no license&quot;

It still loads the module (it doesn't print anything to stdout), but do either of you have any thoughts on this message?

Thanks,
-bitwise
 
Nevermind, I got it. I need to have:

MODULE_LICENSE(&quot;GPL&quot;);

in order to remove that warning. Basically, you have to have a valid license agreement assoicated with your module. It still doesn't print anything to stdout, but that is a priority issue, which I thought &quot;<1>&quot; in the prink took care off, but I'm sure there is something else I'm missing. Thanks for your insight guys, if you have any other tips feel free to post.

-bitwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top