LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   a simple kernel module (https://www.linuxquestions.org/questions/programming-9/a-simple-kernel-module-275923/)

hari_sasidharan 01-09-2005 11:11 PM

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 ?



~
~
~
~
~
~
"hello.c

shishir 01-12-2005 11:18 PM

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 purpose..you might have to put an extra compiler switch like : -nostdinc (to prevent it from picking /usr/include stuff)..


Nerox 01-14-2005 11:22 AM

shishir: hari_sasidharan has already defined MODULE and __KERNEL__, look at the code source.

sripurna007 01-15-2005 01:11 AM

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.


All times are GMT -5. The time now is 08:44 AM.