swappo1
November 17th, 2008, 07:11 AM
Hello,
I am trying to compile and run my first module. I am using the following tutorial: http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN121 I save the following in hello-1.c:
/*
* 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");
}
My problem is with the Makefile. The example provides me with the following:
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
I created this file in gedit and saved it as hello-1.o. I am not sure if this is what I was supposed to do or not since it is not specific on how to proceed. It then says to "compile the module by issuing the command make", however I don't know how to do this and I could not find a tutorial on google. Does anybody know how to compile and run this? Thanks
I am trying to compile and run my first module. I am using the following tutorial: http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN121 I save the following in hello-1.c:
/*
* 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");
}
My problem is with the Makefile. The example provides me with the following:
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
I created this file in gedit and saved it as hello-1.o. I am not sure if this is what I was supposed to do or not since it is not specific on how to proceed. It then says to "compile the module by issuing the command make", however I don't know how to do this and I could not find a tutorial on google. Does anybody know how to compile and run this? Thanks