I am new to kernel programming. I ahve written a hello world program but I am not able to complie it. I have serached and so made a make file under /usr/src and then doing sudo make command to run it. But its giving the following error:
make -C /lib/modules/3.2.0-23-generic-pae/build M=/usr/src modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
make[2]: *** No rule to make target `/usr/src/hello.c', needed by `/usr/src /hello.o'. Stop.
make[1]: *** [_module_/usr/src] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
make: *** [all] Error 2
make file:
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
hello.c (in ~Desktop/inet/)
#include <linux/module.h>
#include <linux/kernel.h>
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");
}
In makefile I have taken care that every new line has a tab space only!
Please can some tell the problem!
Milind Dumbare :
Move your Makefile to where the module source hello.c is. That means in ~/Desktop/inet/. Looks like you have put the Makefile in /usr/src/\n\n$ sudo mv /usr/src/Makefile ~/Desktop/inet/\n$ cd ~/Desktop/inet/\n$ make\n",
2015-03-06T14:01:53