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.
Hello
I am new in making module in linux ,I tried the first module programming as you see as follows
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
Then the tutorials told me for compiling the module I should use the following commands
obj-m += hello-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
would you please explain me what is $(sehll uname –r) and M=$(PWD)
I guess that what you have put above is the Makefile
PS: please put all the code inside <code> </code> tags so that the indendation is clear.
now for makefiles
$(shell uname -r) would run the command uname -r and put the output instead same for M=$(PWD)
so
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
would get replaced by
make -C /lib/modules/2.6.9-1.667/build M=/home/myself/sources/
or something like that where the 2.6... is your version of the kernel and /home/myself/sources is the directory where you have the sources (current directory).
-C instructs the make command to change to the directory before doing anything.
The M=$PWD is used by the build/Makefile
if you check that you will see this line
# Use make M=dir to specify directory of external module to build
Hello and thank you very much for your responce
I tried to do what you recommended me as follows
$ make -c /lib/modules/2.6.4-override-default/build M=/home/linux/hello-1.c
but it sent me back the following error:
bach:Make :command nout found
Please help me
sincerely yours Mohsena
I think you have not installed the make package.
try installing that.
and the command is
<code>
make -c /lib/modules/2.6.4-override-default/build M=/home/linux/
</code>
better
just enter the stuff as it to a text file named Makefile and then
do a make
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.