Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-09-2005, 11:11 PM   #1
LQ Newbie
Registered: Jan 2005
Posts: 4

Rep: Reputation: 0
Exclamation a simple kernel module

this is the sample code that i tried to compile in my kernel 2.4-20.8 machine
as gcc -c hello.c

# define __KERNEL__
# define MODULE

# include <linux/module.h>
# include <linux/kernel.h>
# include <linux/fs.h>

int init_module(void)
struct file_operations fops;
return 0;

void cleanup_module(void)

i referred /usr/include/linux/fs.h and the declaration for file_operations was missing
but according to the book by alessandro rubini & corbet they are there in fs.h

what is wrong and where ?

Old 01-12-2005, 11:18 PM   #2
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
fist you dont use the standard includes to compile a kernel module..
you have to use the kernel headers..from whereever your kernel source is : most of the time /usr/src/linux/include and then you have to specify -DMODULE -D__KERNEL__ to specify that this is for the kernel..

please read the linux device drivers...before starting with the core kernel stuff.. it does give you a sample makefile for the might have to put an extra compiler switch like : -nostdinc (to prevent it from picking /usr/include stuff)..

Last edited by shishir; 01-12-2005 at 11:22 PM.
Old 01-14-2005, 11:22 AM   #3
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
shishir: hari_sasidharan has already defined MODULE and __KERNEL__, look at the code source.
Old 01-15-2005, 01:11 AM   #4
LQ Newbie
Registered: Jan 2005
Posts: 3

Rep: Reputation: 0
Well the compilation works with the command line statement that he has used. try grepping the file_operations from the directory /usr/include. It must be in the fs.h.


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
Simple Linux Kernel Module Problem for 2.4.31 KneeLess Programming 3 08-19-2005 09:59 PM
Problems building a simple kernel module for kernel 2.6.7 atticman Linux - Software 2 12-13-2004 03:35 PM
'Invalid module format' loading simple module on Suse Linux Professional 9.1 rocketdude Linux - Distributions 3 07-27-2004 11:40 PM
adding simple module to kernel(2.6) qfupa Linux - General 5 07-15-2004 06:13 AM
Problem adding a simple kernel module in 2.6 palbox2003 Linux - Software 2 07-14-2004 03:23 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration