ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
(Do you really think kernel programming is for beginners?)
You should have a file called /usr/include/linux/module.h -- if not, you have to install package kernel-source or kernel-headers.
PS: and please use those famous [code] and [/code] tags; you have been asked countless times to do so.
Sir , please help me , i want to create my own product in c langauge but i know that i have not enough knowledge for creating that product , so i am trying this .
but i am beginner !
please give me solution , i love c language , but its too typical for me , to join the programming of device drivers , i want to code at higher level , like where i can create something good !
&you know , whenever i see your comment , i think that today i will get something new from you !
Last edited by tushar_pandey; 07-29-2012 at 04:11 PM.
You do NOT need to be root (via sudo) to compile your Kernel module into a kernel object file. You will however need to be root to install (insmod) and remove (rmmod) it from the running kernel.
If any of what I have stated is above your current comprehension, then I suggest that you pursue learning the basics of C programming, then move on perhaps to learning about Makefiles. A good online tutorial for C programming is available for download at: http://beej.us/guide/bgc/
You should ask help from a competent linux-admin to do the following things:
1. install kernel source under /usr/src/linux
Not every Linux distro uses the location /usr/src/linux; perhaps Debian does, but Ubuntu and Redhat/Fedora do not.
However, it is my understanding that the "universal" way to locate the Linux header files is to reference /lib/modules/`uname -r`/build. This target is a symbolic link to the location where the Kernel Header files are located; for example, on my Fedora 16 system, this is at /usr/src/kernels/3.4.2.-1.fc16.x86_64. Under Kubuntu 12.04, it is located at /usr/src/linux-headers-3.2.0-24-generic.
If the OP is unable to locate "linux/module.h", then they need to install the Kernel Header files. How that is accomplished varies from one distro to another. The OP should first attempt to use his system's package manager.
That does indeed seems like a great tutorial. But the section containing information on how to build a module is incorrect (and has a syntax error). Aside from the hard-coded Kernel version number (which the author acknowledged may not be the same for other systems), not every system stores kernel header files in /usr/src. The usage of "pwd" is also incorrect. In summary, the command will not work on all systems.
The proper way is to use something like:
Code:
make -C /lib/modules/`uname -r`/build M=`pwd` modules
If one hates to type lengthy commands such as the one above, then the solution is to augment the Makefile to contain a similar statement. The OP can refer to my previous post for an example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.