LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2005, 05:52 PM   #1
axr0284
LQ Newbie
 
Registered: Mar 2004
Distribution: Debian
Posts: 15

Rep: Reputation: 0
compiling kernel modules


Hi,
I have been trying to compile and insert a simple kernel module but without luck. This is what I did.
Since the freshly installed debian sarge 3.1 distro did not have any source files under /usr/src, I di uname -a to make sure of the kernel version that is installed:
Linux test 2.4.27-2-386 #1 Mon May 16 16:47:51 JST 2005 i686 GNU/Linux

and then I downloaded the kernel-source-2.4.27.tar.bz2, unziped and untarred it. I then copied this program from a book into example.c:
Code:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
static char __initdata hellomessage[] = KERN_NOTICE "Hello, world!\n";
static char __exitdata byemessage[] = KERN_NOTICE "Goodbye, cruel world.\n";
static int __init start_hello_world(void)
{
   printk(hellomessage);
   return 0;
}
static void __exit go_away(void)
{
   printk(byemessage);
}
module_init(start_hello_world);
module_exit(go_away);
I then compiled it using
gcc -DMODULE -D__KERNEL__ -I/usr/src/kernel-source-2.4.27/include -c example.c


I tried inserting it into the kernel using
/sbin/insmod example.o

but this is the message I got back:

example.o: kernel-module version mismatch
example.o was compiled for kernel version 2.6.0
while this kernel is version 2.4.27-2-386.
example.o: cannot create /var/log/ksymoops/20051125172050.ksyms Permission denied

I don't understand how it could have been compiled for a version of the kernel that I did not use. Thanks in advance.
Amish
 
Old 11-26-2005, 10:17 AM   #2
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 237

Rep: Reputation: 24
just a thought, perhaps you a running the 2.6 kernel. and when you attempt to compile this kernel module, it looks into your existing and running kernel headers?
 
Old 11-26-2005, 03:08 PM   #3
axr0284
LQ Newbie
 
Registered: Mar 2004
Distribution: Debian
Posts: 15

Original Poster
Rep: Reputation: 0
Hi,
Well Almut Behrens on the debian mailing list was good enough to enlighten me. Here is his answer. Hopefully it will be helpful to someone else:

If you want to build kernel modules, you need to use the kernel headers
> _as configured for your current kernel_. The generic header files which
> come with the original kernel sources won't work...
>
> For a stock debian kernel such as 2.4.27-2-386, it's probably easiest
> to just install the respective packages
>
> * kernel-headers-2.4.27-2-386 (or kernel-headers-2.4-386 for that
> matter, which depends on kernel-headers-2.4.27-2-386), and
>
> * kernel-headers-2.4.27-2 (containing the header files common to all
> architectures, referenced via symlinks from within the -386 package).
>
> Then set your include path
> to -I/usr/src/kernel-headers-2.4.27-2-386/include.
>
> I'm not entirely sure how you got that 2.6.0 version into your module,
> but I guess the following happened: as there's no "version.h" in the
> unconfigured kernel sources, the file /usr/include/linux/version.h
> probably got pulled in instead (because it's on the standard include
> path)... However, these include files (though they're kernel headers,
> too) belong to libc, and must not necessarily match the current kernel
> version (in fact, I believe those in sarge are version 2.6.0 -- btw,
> this is the package linux-kernel-headers).
>
> If you're interested in what went wrong in your original attempt, you
> could run just the preprocessor (-E), and grep for version.h in its output
>
> gcc -DMODULE -D__KERNEL__ -I/usr/src/kernel-source-2.4.27/include -E
> example.c | grep version.h
>
> I'd think you see something like "# 1 "/usr/include/linux/version.h" 1
> 3"...
>
> Cheers,
> Almut
 
  


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
Modules in Kernel Compiling SlackwareInAZ Slackware 1 07-29-2005 05:10 AM
need some help in Compiling Kernel modules bharat83 SUSE / openSUSE 1 01-07-2005 07:21 AM
Compiling Modules for 2.6.6 kernel! Bigg Mike Linux - Newbie 9 06-09-2004 09:04 PM
Compiling kernel modules? jrjarrett Linux - Software 0 09-09-2003 10:24 AM
compiling modules for a running kernel bass Linux - Newbie 3 11-16-2002 04:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:25 AM.

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
Open Source Consulting | Domain Registration