Click to See Complete Forum and Search --> : this is a real test for programming GURUS


mnsharif
10-16-2002, 02:45 AM
hi all

i am styudying Linux for the last two-three months. and before that i knew only that Linux is an Operating Sytem, nothing else.

Well by this standard i have done quie well, and learned much about filesystems and VFS its conceptual and concrete architecture and stuff like that. Now actually i was assigned a work to change a VFS to make it a Distributed File System.

Then i started studying "The Linux Kernel Module Programming Guide 2001 version" (commonly knows as "lkmpg") and i was surprised coz the approach the autor used was brilliant, and i thought it would be very easy to run my first program. But when i typed it in (actually i just did copy-paste) and compiled (make) it. It showed a lot of errors. I had no idea about those.

SO I WANT ATLEAST MY FIRST PROGRAM TO RUN & anyone who have read "lkmpg" and have tried the codes, please let me know

also there is a problem there is also a version of the same book available but that is 1999 edition and i browsed through it, its code samples were a bit different too. Anyone got any idea????


I WILL BE SO THANKFUL FOR ANYONE WHO HELP.


thanx again

bwkaz
10-16-2002, 01:14 PM
Well, I don't know what the code he's using looks like... is this book freely available, like on the Internet somewhere? If so, could you provide a link?

What were the first few errors you got when trying to run make?

<dumb question>You did try doing this from inside the kernel source tree, right? </dumb question>

Hooloovoo
10-16-2002, 01:51 PM
The entire book (er well at least a lot of it) is available online here (http://www.tldp.org/LDP/lkmpg/node1.html) And no, you don't need to compile a module from within the kernel source tree.

That said, could you please post the specific errors? Are the errors occurring when you compile, or when you try to run insmod? If insmod complains about the license, put MODULE_LICENSE("GPL"); somewhere in your code (in the file that does not define __NO_VERSION__).

mnsharif
10-17-2002, 04:57 AM
well, thanx for your concern,


First of all the link "Hooloovoo" has given is an old one. The one i read and the code i used is given in a newer version of the same document available at NEW_VERSION (http://www.dirac.org/linux/writing/lkmpg/lkmpg.html)


Well, for your convinience the code i typed in was (the very first example of the lkmpg)

/******************/
/*CODE STARTS HERE*/

/* hello-1.c - The simplest kernel module.*/

#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */


int init_module(void)
{
printk("<1>Hello world 1.\n");
return 0;
}

void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}

/*CODE ENDS HERE*/
/******************/



and the contents of Makefile, i used were


/*********************************************/
# Makefile for a basic kernel module

CC=gcc
CFLAGS := -c -0 -W -Wall -Wstrict-prototypes -Wmissing-prototypes
MODFLAGS := -DMODULE -D__KERNEL__

hello-1.o: hello.c
${CC} ${MODCFLAGS} hello.c
/*********************************************/


and the error i got is displayed in a png snapshot.

Well, i read in the LKMPG book that i must do it at console not from X. Although the png attached is taken when i make the file in X, without it, the same error was displayed.


I think, now you will be clear


i m waiting for the response

bwkaz
10-17-2002, 10:14 AM
You're using the wrong linux/module.h and linux/kernel.h files... ;)

The copies that are under /usr/include are not in sync with the current kernel. They are, instead, in sync with whatever kernel the current glibc was compiled under, which is almost always not the same one.

In the kernel build process, I see a lot of their modules being compiled with the -nostdinc option being passed to gcc, so it doesn't look in /usr/include for the headers. I think that if you change your CFLAGS in your Makefile to look something like this, you'll at least get closer:

CFLAGS := -c -0 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -nostdinc -I/usr/src/linux/include

That way, you'll include /usr/src/linux/include/linux/module.h and /usr/src/linux/include/linux/kernel.h instead of the versions in /usr/include/linux, which I believe will solve this problem at least.

HTH

mnsharif
10-18-2002, 10:09 AM
hi all

i got the previous post saying that the "linux/kernel.h" and "linux/module.h" i m using are the one which are not in sync with current kernel version. And he was right!! both "kernel.h" (one /usr/include/linux/kernel.h and other /usr/src/linux-2.4.18-3/include/linux/kernel.h) were totally different. So i changed the path to include the headers from "/usr/src/linux-2.4.18-3/include" through -I option of gcc in the Makefile. But by doing this i got the error that call from
hello.c -> kernel.h -> stdarg.h
and stdarg.h is not available.

and i search all along the directories, there was no file with the same name.


and with the old set of include files (from /usr/include) i get the error that there is a parse error where a union is defined. I commented out the Union declaration and recompiled, it didnt showed any error. then i did insmod and it replied that the module compiled is for kernel version 2.4.9-9 while the current version is 2.4.18-3.


What should i do??

Well, i m sure that the author of the lkmpg was right, when he said that running the first programme is the trick then its smooth sailing.

Hope you will try to help me out (again :))

take care.

EscapeCharacter
10-18-2002, 04:08 PM
find where stdarg.h is on your system and add that as a include directory also, worked for me

bwkaz
10-18-2002, 06:24 PM
Oh...

I replied to your email asking me this same question.

Add /usr/lib/gcc-lib/i686-pc-linux-gnu/<gcc version here>/include to your include path.