Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hiiii every body i am just a beginner in kernel module programming.
i want help regarding it .
i have written a simple module and trying to complie it but it is giving the error that linux/module.h file is not there though i have seprately specified the pat of file but then dependencies are missing please help me out......
thanx in advance.
Last edited by sniffer_raghav; 10-02-2007 at 01:58 PM.
hiii....
i have written a simple module which is as follows
#include <linux/module.h>
int init_module(void)
{
printk("<1>Hello, world\n");
return 0;
}
void cleanup_module(void)
{
printk("<1>Goodbye cruel world\n");
}
first the error was that linux/module.h
file not found ..............
then i gave the path where file is but it is giving dependencies error .........
can u suggest me any tutorial or sol of this prob ..........
thanx in advance......
first the error was that linux/module.h
file not found ..............
then i gave the path where file is but it is giving dependencies error .........
can u suggest me any tutorial or sol of this prob ..........
thanx in advance......
Well, you haven’t told us how you are building this module. Since the error is occurring during building, it would seem this is an important detail…
In any case, the recommended method of compilation is to use the kernel’s own build system. E.g., for a simple, one-file module try something like this:
Code:
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $filename .c).o"
(where $filename is the name of your C sourcefile).
You can read more about the 2.6 kernel build system in just about any kernel programming guide or tutorial.
i m buliding this module by following set of command
first im creating object file by
#gcc -c -i hello.c
Well, that’s your problem then…
Quote:
Originally Posted by sniffer_raghav
and the command u have suggested i have tried
it is giving this >
I suggest you carefully look at the command suggested, and make sure you copy-and-paste it correctly. For example, if my file is called hello.c, this is what I do:
Code:
filename=hello.c
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $filename .c).o"
By all means, look at the literally-hundreds of existing modules that are available in your Linux distro! (You might have to install "source" packages to see them.)
The most common way to approach any kernel-module is to find something that's "almost" what you want, then practice installing it, and then use it as a starting-point. "If you are starting from scratch, on anything, you are doing something wrong."
thank you sir ,
sir i have tried wat you told me to do ...........
again i am getting error that is given below...........
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $hello .c).o"
make: Entering directory `/usr/src/kernels/linux-2.6.23'
LD /root/device/built-in.o
make[1]: *** No rule to make target `/root/device/.c.c', needed by `/root/device/.c.o'. Stop.
make: *** [_module_/root/device] Error 2
make: Leaving directory `/usr/src/kernels/linux-2.6.23'
please read it and reply.......
i have also compiled a new kernle 2.6.23
and have includede all the kernel headers .......
though my prob is not solved...........
please help me out ...........
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $hello .c).o"
Hmmm… What could be the problem?
Quote:
Originally Posted by sniffer_raghav
please read it and reply.......
It doesn’t look like you’ve looked at any of the seven links I had in my last post. In fact, you barely managed to read my post (you seem to have missed an entire line).
sir i have read the pdf you have provided and followed the things given dere .........
but prob is not solved the prob i m getting is below.............
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $hello .c).o"
make: Entering directory `/usr/src/kernels/2.6.21-1.3194.fc7-i686'
make[1]: *** No rule to make target `/root/device/.c.c', needed by `/root/device/.c.o'. Stop.
make: *** [_module_/root/device] Error 2
make: Leaving directory `/usr/src/kernels/2.6.21-1.3194.fc7-i686'
please sir tell y dis error is occuring ..........
thanx for the material provided ...........
First, did you not see the highlighted string from my previous post?
Quote:
Originally Posted by sniffer_raghav
sir i have read the pdf you have provided and followed the things given dere .........
but prob is not solved the prob i m getting is below.............
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $hello .c).o"
Had you read any of those articles, you would have found that the obj-m should hold a list of object files which shall be linked to be loadable kernel object files. The dependency resolution shall assume (this assumption may be overridden) that the sole source file corresponding to said object file has the same basename (without extension) and has extension “.c”.
So if you want a kernel object file named “foo.ko”, you would set “obj-m=foo.o”, and the kernel build system would compile such an object from the file “foo.c”. Conversely, if you have a source file named “bar.c” and wanted to compile it, you would set “obj-m=bar.o”, and the end-result would be a file named “bar.ko”.
Now, suppose you have a file named “hello.c”. How do you go about compiling it? You could do this:
Code:
hello=hello.c
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename $hello .c).o"
Or this:
Code:
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="$(basename hello.c .c).o"
Or even this:
Code:
make -C "/lib/modules/$(uname -r)/build" M=$PWD obj-m="hello.o"
sir,
i have tread all those links and was successful in loading and
umloading the module. the problem is solved.now when i have written a module and loaded it tell me the next step to follow for learning the programming.
thank you for the co operation.
as taken from a e-book on module and device drivers programming for the 2.6.* kernels.
but i was getting errors :
make: Entering directory `/usr/src/linux-2.6.23.1'
scripts/Makefile.build:33: /root/Makefile: No such file or directory
make[1]: *** No rule to make target `/root/Makefile'. Stop.
make: *** [_module_/root] Error 2
make: Leaving directory `/usr/src/linux-2.6.23.1'
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
static int hello3_data __initdata = 3;
static int __init hello_3_init(void)
{
printk(KERN_INFO "Hello, world %d\n", hello3_data);
return 0;
}
static void __exit hello_3_exit(void)
{
printk(KERN_INFO "Goodbye, world 3\n");
}
module_init(hello_3_init);
module_exit(hello_3_exit);
sir i have successfully compiled the above code but problem is that
printk is not giving message on the terminal ......
y is it so sir explain ...........
thank you..........
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.